diff --git a/api/save_lpa.php b/api/save_lpa.php index c7e82f7..231db69 100644 --- a/api/save_lpa.php +++ b/api/save_lpa.php @@ -161,6 +161,26 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $postcode = $_POST['postcode'] ?? ''; $next_action = $_POST['next_action'] ?? 'add_another'; + // Check if all primary fields are empty + $is_empty = empty($first_name) && empty($last_name) && empty($email) && empty($dob) && empty($address1) && empty($town) && empty($postcode); + + if ($is_empty) { + // If empty, check if we have at least one attorney + $check = db()->prepare("SELECT count(*) FROM lpa_attorneys WHERE lpa_id = ? AND type = 'primary'"); + $check->execute([$lpa_id]); + $count = (int)$check->fetchColumn(); + + if ($count > 0) { + // Success, move to next step if requested + $next_step = ($next_action === 'next_step') ? 3 : 2; + echo json_encode(['success' => true, 'id' => (int)$lpa_id, 'next_step' => $next_step, 'message' => 'Moving to next step.']); + exit; + } else { + echo json_encode(['success' => false, 'error' => 'At least one attorney must be added.']); + exit; + } + } + if (empty($first_name) || empty($last_name) || empty($email) || empty($dob) || empty($address1) || empty($town) || empty($postcode)) { echo json_encode(['success' => false, 'error' => 'All fields are required to save an attorney.']); exit; diff --git a/apply.php b/apply.php index 096d17f..d35b741 100644 --- a/apply.php +++ b/apply.php @@ -164,7 +164,7 @@ foreach ($notified_persons as $np) {
Please select the type of LPA and provide the donor's details and address. You can save your progress and return later.
@@ -252,7 +252,7 @@ foreach ($notified_persons as $np) {Provide the details of the person who will witness the donor's signature.
If you appointed attorneys jointly, they must all register the LPA together.