| @@ -1,18 +1,13 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * @copyright © TMS-Plugins. All rights reserved. | |
| 4 | + * @copyright © Melograno Venture Studio. All rights reserved. | |
| 5 | 5 | * @licence See COPYING.md for license details. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace IvyForms\Controllers\Form; |
| 9 | 9 | |
| 10 | -// phpcs:disable PSR1.Files.SideEffects | |
| 11 | -if (!defined('ABSPATH')) { | |
| 12 | - exit; // Exit if accessed directly | |
| 13 | -} | |
| 14 | - | |
| 15 | 10 | use IvyForms\Common\Exceptions\ForbiddenException; |
| 16 | 11 | use IvyForms\Common\Exceptions\InvalidArgumentException; |
| 17 | 12 | use IvyForms\Common\Exceptions\NotFoundException; |
| 18 | 13 | use IvyForms\Common\Exceptions\QueryExecutionException; |
| @@ -41,10 +36,10 @@ | ||
| 41 | 36 | FormService $formService, |
| 42 | 37 | FieldService $fieldService, |
| 43 | 38 | ConfirmationService $confirmationService |
| 44 | 39 | ) { |
| 45 | - $this->formService = $formService; | |
| 46 | - $this->fieldService = $fieldService; | |
| 40 | + $this->formService = $formService; | |
| 41 | + $this->fieldService = $fieldService; | |
| 47 | 42 | $this->confirmationService = $confirmationService; |
| 48 | 43 | } |
| 49 | 44 | |
| 50 | 45 | /** |
| @@ -64,27 +59,23 @@ | ||
| 64 | 59 | throw new InvalidArgumentException( |
| 65 | 60 | BackendStrings::getExceptionStrings()['invalid_request_data'] |
| 66 | 61 | ); |
| 67 | 62 | } |
| 63 | + | |
| 68 | 64 | // Sanitize the input data |
| 69 | 65 | $formId = Sanitizer::sanitizeId($data->get_param('id')); |
| 70 | 66 | |
| 71 | - $form = $this->formService->getFormById($formId); | |
| 72 | - | |
| 73 | - // Use the service to get fields with options | |
| 67 | + $form = $this->formService->getFormById($formId); | |
| 74 | 68 | $fieldsMap = $this->fieldService->getAllFieldsWithOptions($form->getId()); |
| 75 | 69 | $form->setFields($fieldsMap); |
| 76 | 70 | |
| 77 | - $confirmationsArr = $this->confirmationService->getConfirmationsById($formId); | |
| 71 | + $defaultConfirmationId = $this->confirmationService->ensureDefaultConfirmationExists($formId); | |
| 78 | 72 | |
| 79 | - $confirmations = []; | |
| 80 | - | |
| 81 | - foreach ($confirmationsArr as $confirmation) { | |
| 82 | - $confirmations[] = $confirmation->toArray(); | |
| 83 | - } | |
| 84 | - | |
| 85 | 73 | return new WP_REST_Response([ |
| 86 | 74 | 'message' => BackendStrings::getCommonStrings()['ok'], |
| 87 | - '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 | + ]), | |
| 88 | 79 | ], 200); |
| 89 | 80 | } |
| 90 | 81 | } |