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 +21 -32 0.2 → 1.5.1 View file →
@@ -1,21 +1,18 @@
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;
14 +use IvyForms\Common\Exceptions\ValidationException;
18 15 use IvyForms\Common\Sanitizer\Sanitizer;
19 16 use IvyForms\Controllers\Controller;
20 17 use IvyForms\Services\Confirmation\ConfirmationService;
21 18 use IvyForms\Services\Field\FieldService;
@@ -33,25 +30,25 @@
33 30 {
34 31 private FormService $formService;
35 32 private FieldService $fieldService;
36 33 private ConfirmationService $confirmationService;
34 +
37 35 public function __construct(
38 36 FormService $formService,
39 37 FieldService $fieldService,
40 38 ConfirmationService $confirmationService
41 39 ) {
42 - $this->formService = $formService;
43 - $this->fieldService = $fieldService;
40 + $this->formService = $formService;
41 + $this->fieldService = $fieldService;
44 42 $this->confirmationService = $confirmationService;
45 43 }
46 44
47 45 /**
48 46 * @param WP_REST_Request $data
49 - *
50 47 * @return WP_REST_Response
51 - *
52 48 * @throws NotFoundException
53 - * @throws InvalidArgumentException|ForbiddenException
49 + * @throws InvalidArgumentException|ForbiddenException|ValidationException
50 + * @throws QueryExecutionException
54 51 */
55 52 public function handle(WP_REST_Request $data): WP_REST_Response
56 53 {
57 54 // Verify the nonce
@@ -56,37 +53,29 @@
56 53 {
57 54 // Verify the nonce
58 55 Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
59 56
60 - // Check if the form ID is provided
57 + // Check if the form ID is provided
61 58 if (empty($data->get_params())) {
62 - throw new InvalidArgumentException('Invalid request data.');
59 + throw new InvalidArgumentException(
60 + BackendStrings::getExceptionStrings()['invalid_request_data']
61 + );
63 62 }
63 +
64 64 // Sanitize the input data
65 65 $formId = Sanitizer::sanitizeId($data->get_param('id'));
66 66
67 - $form = $this->formService->getFormById($formId);
67 + $form = $this->formService->getFormById($formId);
68 + $fieldsMap = $this->fieldService->getAllFieldsWithOptions($form->getId());
69 + $form->setFields($fieldsMap);
68 70
69 - $fields = $this->fieldService->getAllFields($form->getId());
71 + $defaultConfirmationId = $this->confirmationService->ensureDefaultConfirmationExists($formId);
70 72
71 - $fieldsMap = [];
72 -
73 - $confirmationsArr = $this->confirmationService->getConfirmationsById($formId);
74 -
75 - $confirmations = [];
76 -
77 - foreach ($confirmationsArr as $confirmation) {
78 - $confirmations[] = $confirmation->toArray();
79 - }
80 -
81 - foreach ($fields as $field) {
82 - $fieldsMap[] = $field->toArray();
83 - }
84 -
85 - $form->setFields($fieldsMap);
86 -
87 73 return new WP_REST_Response([
88 74 'message' => BackendStrings::getCommonStrings()['ok'],
89 - '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 + ]),
90 79 ], 200);
91 80 }
92 81 }