| @@ -36,10 +36,10 @@ | ||
| 36 | 36 | FormService $formService, |
| 37 | 37 | FieldService $fieldService, |
| 38 | 38 | ConfirmationService $confirmationService |
| 39 | 39 | ) { |
| 40 | - $this->formService = $formService; | |
| 41 | - $this->fieldService = $fieldService; | |
| 40 | + $this->formService = $formService; | |
| 41 | + $this->fieldService = $fieldService; | |
| 42 | 42 | $this->confirmationService = $confirmationService; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
| @@ -59,27 +59,23 @@ | ||
| 59 | 59 | throw new InvalidArgumentException( |
| 60 | 60 | BackendStrings::getExceptionStrings()['invalid_request_data'] |
| 61 | 61 | ); |
| 62 | 62 | } |
| 63 | + | |
| 63 | 64 | // Sanitize the input data |
| 64 | 65 | $formId = Sanitizer::sanitizeId($data->get_param('id')); |
| 65 | 66 | |
| 66 | - $form = $this->formService->getFormById($formId); | |
| 67 | - | |
| 68 | - // Use the service to get fields with options | |
| 67 | + $form = $this->formService->getFormById($formId); | |
| 69 | 68 | $fieldsMap = $this->fieldService->getAllFieldsWithOptions($form->getId()); |
| 70 | 69 | $form->setFields($fieldsMap); |
| 71 | 70 | |
| 72 | - $confirmationsArr = $this->confirmationService->getConfirmationsById($formId); | |
| 71 | + $defaultConfirmationId = $this->confirmationService->ensureDefaultConfirmationExists($formId); | |
| 73 | 72 | |
| 74 | - $confirmations = []; | |
| 75 | - | |
| 76 | - foreach ($confirmationsArr as $confirmation) { | |
| 77 | - $confirmations[] = $confirmation->toArray(); | |
| 78 | - } | |
| 79 | - | |
| 80 | 73 | return new WP_REST_Response([ |
| 81 | 74 | 'message' => BackendStrings::getCommonStrings()['ok'], |
| 82 | - 'data' => array_merge($form->toArray(), ['confirmationId' => $confirmations[0]['id']]) | |
| 75 | + 'data' => array_merge($form->toArray(), [ | |
| 76 | + 'confirmationId' => $defaultConfirmationId, | |
| 77 | + 'submissionNonce' => wp_create_nonce('ivyformsFrontSubmissionNonce_' . $formId), | |
| 78 | + ]), | |
| 83 | 79 | ], 200); |
| 84 | 80 | } |
| 85 | 81 | } |