PluginProbe
The Innovative Form Builder – IvyForms / 1.5.1
The Innovative Form Builder – IvyForms v1.5.1
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
← All changes | backend/src/Controllers/Form/GetFormController.php +16 -28 0.4 → 1.5.1 View file →
@@ -1,21 +1,17 @@
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;
13 +use IvyForms\Common\Exceptions\QueryExecutionException;
18 14 use IvyForms\Common\Exceptions\ValidationException;
19 15 use IvyForms\Common\Sanitizer\Sanitizer;
20 16 use IvyForms\Controllers\Controller;
21 17 use IvyForms\Services\Confirmation\ConfirmationService;
@@ -21,9 +17,8 @@
21 17 use IvyForms\Services\Confirmation\ConfirmationService;
22 18 use IvyForms\Services\Field\FieldService;
23 19 use IvyForms\Services\Form\FormService;
24 20 use IvyForms\Services\Translations\BackendStrings;
25 -use IvyForms\Repository\FieldOptions\FieldOptionsRepository;
26 21 use WP_REST_Request;
27 22 use WP_REST_Response;
28 23
29 24 /**
@@ -35,28 +30,25 @@
35 30 {
36 31 private FormService $formService;
37 32 private FieldService $fieldService;
38 33 private ConfirmationService $confirmationService;
39 - private FieldOptionsRepository $fieldOptionsRepository;
34 +
40 35 public function __construct(
41 36 FormService $formService,
42 37 FieldService $fieldService,
43 - ConfirmationService $confirmationService,
44 - FieldOptionsRepository $fieldOptionsRepository
38 + ConfirmationService $confirmationService
45 39 ) {
46 - $this->formService = $formService;
47 - $this->fieldService = $fieldService;
40 + $this->formService = $formService;
41 + $this->fieldService = $fieldService;
48 42 $this->confirmationService = $confirmationService;
49 - $this->fieldOptionsRepository = $fieldOptionsRepository;
50 43 }
51 44
52 45 /**
53 46 * @param WP_REST_Request $data
54 - *
55 47 * @return WP_REST_Response
56 - *
57 48 * @throws NotFoundException
58 49 * @throws InvalidArgumentException|ForbiddenException|ValidationException
50 + * @throws QueryExecutionException
59 51 */
60 52 public function handle(WP_REST_Request $data): WP_REST_Response
61 53 {
62 54 // Verify the nonce
@@ -61,33 +53,29 @@
61 53 {
62 54 // Verify the nonce
63 55 Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
64 56
65 - // Check if the form ID is provided
57 + // Check if the form ID is provided
66 58 if (empty($data->get_params())) {
67 59 throw new InvalidArgumentException(
68 60 BackendStrings::getExceptionStrings()['invalid_request_data']
69 61 );
70 62 }
63 +
71 64 // Sanitize the input data
72 65 $formId = Sanitizer::sanitizeId($data->get_param('id'));
73 66
74 - $form = $this->formService->getFormById($formId);
75 -
76 - // Use the service to get fields with options
77 - $fieldsMap = $this->fieldService->getAllFieldsWithOptions($form->getId(), $this->fieldOptionsRepository);
67 + $form = $this->formService->getFormById($formId);
68 + $fieldsMap = $this->fieldService->getAllFieldsWithOptions($form->getId());
78 69 $form->setFields($fieldsMap);
79 70
80 - $confirmationsArr = $this->confirmationService->getConfirmationsById($formId);
71 + $defaultConfirmationId = $this->confirmationService->ensureDefaultConfirmationExists($formId);
81 72
82 - $confirmations = [];
83 -
84 - foreach ($confirmationsArr as $confirmation) {
85 - $confirmations[] = $confirmation->toArray();
86 - }
87 -
88 73 return new WP_REST_Response([
89 74 'message' => BackendStrings::getCommonStrings()['ok'],
90 - '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 + ]),
91 79 ], 200);
92 80 }
93 81 }