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/Confirmation/AddConfirmationController.php +14 -8 0.1.2 → 1.5 View file →
@@ -1,13 +1,8 @@
1 1 <?php
2 2
3 3 namespace IvyForms\Controllers\Confirmation;
4 4
5 -// phpcs:disable PSR1.Files.SideEffects
6 -if (!defined('ABSPATH')) {
7 - exit; // Exit if accessed directly
8 -}
9 -
10 5 use IvyForms\Common\Exceptions\ForbiddenException;
11 6 use IvyForms\Common\Exceptions\InvalidArgumentException;
12 7 use IvyForms\Common\Exceptions\QueryExecutionException;
13 8 use IvyForms\Common\Sanitizer\Sanitizer;
@@ -13,8 +8,9 @@
13 8 use IvyForms\Common\Sanitizer\Sanitizer;
14 9 use IvyForms\Controllers\Controller;
15 10 use IvyForms\Factory\Confirmation\ConfirmationFactory;
16 11 use IvyForms\Services\Confirmation\ConfirmationService;
12 +use IvyForms\Services\Translations\BackendStrings;
17 13 use WP_REST_Request;
18 14 use WP_REST_Response;
19 15
20 16 /**
@@ -46,26 +42,36 @@
46 42 Sanitizer::verifyNonce($data->get_header('X-WP-Nonce'));
47 43
48 44 // Validate request data
49 45 if (empty($data->get_params())) {
50 - throw new InvalidArgumentException('Invalid request data.');
46 + throw new InvalidArgumentException(
47 + BackendStrings::getExceptionStrings()['invalid_request_data']
48 + );
51 49 }
52 50
53 51 // Sanitize the input data
54 52 $params = Sanitizer::sanitizeConfirmationData($data->get_params());
55 53
54 + if (empty(trim($params['name'] ?? ''))) {
55 + throw new InvalidArgumentException(
56 + BackendStrings::getSettingsFormBuilderStrings()['confirmation_name_required']
57 + );
58 + }
59 +
56 60 $confirmation = ConfirmationFactory::create($params);
57 61
58 62 $confirmationId = $this->confirmationService->createConfirmation($confirmation);
59 63
60 64 if (!$confirmationId) {
61 - throw new QueryExecutionException('Failed to create confirmation.');
65 + throw new QueryExecutionException(
66 + BackendStrings::getSettingsFormBuilderStrings()['failed_to_create_confirmation']
67 + );
62 68 }
63 69
64 70 $confirmation->setId($confirmationId);
65 71
66 72 return new WP_REST_Response([
67 - 'message' => 'OK',
73 + 'message' => BackendStrings::getCommonStrings()['ok'],
68 74 'data' => $confirmation->toArray()
69 75 ], 200);
70 76 }
71 77 }