lots of front-end work
This commit is contained in:
1 parent
bd9eb7798f
commit
9b98c652ef
4 files changed
+275
-14
No files matched your search
+39
-13
@@ -28,6 +28,26 @@ function callApi(string $method, string $path, $body = null)
|
||||
return json_decode($response, true);
|
||||
}
|
||||
|
||||
// Fetch rate options setting
|
||||
$rateOptionsSetting = callApi('GET', '/settings/rate_options');
|
||||
$rateOptions = [];
|
||||
if ($rateOptionsSetting && isset($rateOptionsSetting['value'])) {
|
||||
$parsed = json_decode($rateOptionsSetting['value'], true);
|
||||
if (is_array($parsed)) {
|
||||
$rateOptions = $parsed;
|
||||
}
|
||||
}
|
||||
|
||||
// Update form handling to process selected rates
|
||||
$selectedRates = $_POST['rates'] ?? [];
|
||||
$ratesArray = [];
|
||||
foreach ($selectedRates as $item) {
|
||||
$parts = explode(':', $item, 2);
|
||||
if (count($parts) == 2) {
|
||||
$ratesArray[] = [$parts[0] => $parts[1]];
|
||||
}
|
||||
}
|
||||
|
||||
$created = null;
|
||||
$errors = [];
|
||||
|
||||
@@ -37,26 +57,26 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$phone = trim($_POST['phone'] ?? '');
|
||||
$age = trim($_POST['age'] ?? '');
|
||||
$photo = trim($_POST['photo'] ?? '');
|
||||
$rates = trim($_POST['rates'] ?? '');
|
||||
$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.'; }
|
||||
if ($rates !== '' && !is_numeric($rates)) { $errors[] = 'Rates 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' => $rates === '' ? null : (float)$rates,
|
||||
'rates' => empty($ratesArray) ? null : $ratesArray,
|
||||
'private'=> $private
|
||||
];
|
||||
$result = callApi('POST', '/providers', $body);
|
||||
if ($result) {
|
||||
$created = $result; // API returns created provider object
|
||||
// On successful creation, redirect to the list providers page
|
||||
header('Location: list_providers.php');
|
||||
exit;
|
||||
} else {
|
||||
$errors[] = 'Failed to create provider. API error.';
|
||||
}
|
||||
@@ -88,20 +108,26 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if ($created): ?>
|
||||
<div class="success">
|
||||
<p>Provider created successfully with ID <?=htmlspecialchars($created['id'] ?? '')?>.</p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<form method="post" action="">
|
||||
<label>Name:<br><input type="text" name="name" value="<?=htmlspecialchars($_POST['name'] ?? '')?>" required></label>
|
||||
<label>Phone:<br><input type="text" name="phone" value="<?=htmlspecialchars($_POST['phone'] ?? '')?>"></label>
|
||||
<label>Age:<br><input type="number" name="age" value="<?=htmlspecialchars($_POST['age'] ?? '')?>"></label>
|
||||
<label>Photo URL:<br><input type="text" name="photo" value="<?=htmlspecialchars($_POST['photo'] ?? '')?>"></label>
|
||||
<label>Rates:<br><input type="text" name="rates" value="<?=htmlspecialchars($_POST['rates'] ?? '')?>"></label>
|
||||
<label><input type="checkbox" name="private" <?=isset($_POST['private'])?'checked':''?>> Private</label>
|
||||
<button type="submit">Create Provider</button>
|
||||
<?php if (!empty($rateOptions)) : ?>
|
||||
<label>Rate Options:<br>
|
||||
<?php foreach ($rateOptions as $option) :
|
||||
$key = key($option);
|
||||
$value = $option[$key];
|
||||
?>
|
||||
<input type="checkbox" name="rates[]" value="<?=htmlspecialchars($key . ':' . $value)?>" <?php if (in_array($key . ':' . $value, $selectedRates)) echo 'checked'; ?>> <?=htmlspecialchars($key)?>: <?=htmlspecialchars($value)?>
|
||||
<?php endforeach; ?>
|
||||
</label>
|
||||
<?php endif; ?>
|
||||
<label><input type="checkbox" name="private" <?=isset($_POST['private'])?'checked':''?>> Private</label><br>
|
||||
<button type="submit" class="btn">Create Provider</button>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
Reference in new issue
Block a user