PluginProbe
The Innovative Form Builder – IvyForms / 1.5
The Innovative Form Builder – IvyForms v1.5
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 +23 -33 0.1.2 → 1.5 View file →
@@ -1,26 +1,24 @@
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;
22 19 use IvyForms\Services\Form\FormService;
20 +use IvyForms\Services\Translations\BackendStrings;
23 21 use WP_REST_Request;
24 22 use WP_REST_Response;
25 23
26 24 /**
@@ -32,25 +30,25 @@
32 30 {
33 31 private FormService $formService;
34 32 private FieldService $fieldService;
35 33 private ConfirmationService $confirmationService;
34 +
36 35 public function __construct(
37 36 FormService $formService,
38 37 FieldService $fieldService,
39 38 ConfirmationService $confirmationService
40 39 ) {
41 - $this->formService = $formService;
42 - $this->fieldService = $fieldService;
40 + $this->formService = $formService;
41 + $this->fieldService = $fieldService;
43 42 $this->confirmationService = $confirmationService;
44 43 }
45 44
46 45 /**
47 46 * @param WP_REST_Request $data
48 - *
49 47 * @return WP_REST_Response
50 - *
51 48 * @throws NotFoundException
52 - * @throws InvalidArgumentException|ForbiddenException
49 + * @throws InvalidArgumentException|ForbiddenException|ValidationException
50 + * @throws QueryExecutionException
53 51 */
54 52 public function handle(WP_REST_Request $data): WP_REST_Response
55 53 {
56 54 // Verify the nonce
@@ -55,37 +53,29 @@
55 53 {
56 54 // Verify the nonce
57 55 Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
58 56
59 - // Check if the form ID is provided
57 + // Check if the form ID is provided
60 58 if (empty($data->get_params())) {
61 - throw new InvalidArgumentException('Invalid request data.');
59 + throw new InvalidArgumentException(
60 + BackendStrings::getExceptionStrings()['invalid_request_data']
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 + $form = $this->formService->getFormById($formId);
68 + $fieldsMap = $this->fieldService->getAllFieldsWithOptions($form->getId());
69 + $form->setFields($fieldsMap);
67 70
68 - $fields = $this->fieldService->getAllFields($form->getId());
71 + $defaultConfirmationId = $this->confirmationService->ensureDefaultConfirmationExists($formId);
69 72
70 - $fieldsMap = [];
71 -
72 - $confirmationsArr = $this->confirmationService->getConfirmationsById($formId);
73 -
74 - $confirmations = [];
75 -
76 - foreach ($confirmationsArr as $confirmation) {
77 - $confirmations[] = $confirmation->toArray();
78 - }
79 -
80 - foreach ($fields as $field) {
81 - $fieldsMap[] = $field->toArray();
82 - }
83 -
84 - $form->setFields($fieldsMap);
85 -
86 73 return new WP_REST_Response([
87 - 'message' => 'OK',
88 - 'data' => array_merge($form->toArray(), ['confirmationId' => $confirmations[0]['id']])
74 + 'message' => BackendStrings::getCommonStrings()['ok'],
75 + 'data' => array_merge($form->toArray(), [
76 + 'confirmationId' => $defaultConfirmationId,
77 + 'submissionNonce' => wp_create_nonce('ivyformsFrontSubmissionNonce_' . $formId),
78 + ]),
89 79 ], 200);
90 80 }
91 81 }