= 400) { return null; // or throw an exception } return json_decode($response, true); } // Fetch rate options setting $rateOptionsSetting = callApi('GET', '/settings/rate_options'); $rateOptions = []; if ($rateOptionsSetting && isset($rateOptionsSetting['value'])) { $rateOptions = explode(',', $rateOptionsSetting['value']); /* $parsed = json_decode($rateOptionsSetting['value'], true); if (is_array($parsed)) { $rateOptions = $parsed; } echo "Rate options:".$rateOptionsSetting['value']; */ } // Update form handling to process selected rates $selectedRateKeys = $_POST['rate_selected'] ?? []; $ratesArray = []; foreach ($selectedRateKeys as $key) { $value = $_POST['rate_value'][$key] ?? '0'; $ratesArray[] = [$key => $value]; } $created = null; $errors = []; if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Collect form data $name = trim($_POST['name'] ?? ''); $phone = trim($_POST['phone'] ?? ''); $age = trim($_POST['age'] ?? ''); $photo = trim($_POST['photo'] ?? ''); $private = isset($_POST['private']) ? true : false; // Basic validation if ($name === '') { $errors[] = 'Name is required.'; } if ($age !== '' && !is_numeric($age)) { $errors[] = 'Age must be a number.'; } // Rates now processed from checkboxes if (empty($errors)) { $body = [ 'name' => $name, 'phone' => $phone, 'age' => $age === '' ? null : (int)$age, 'photo' => $photo === '' ? null : $photo, 'rates' => empty($ratesArray) ? null : $ratesArray, 'private'=> $private ]; $result = callApi('POST', '/providers', $body); if ($result) { // On successful creation, redirect to the list providers page header('Location: list_providers.php'); exit; } else { $errors[] = 'Failed to create provider. API error.'; } } } ?>
=htmlspecialchars($e)?>