PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 1.2.4
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v1.2.4
6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 3.6.66 All 195 releases
fluentform / app / Modules / Form / Settings / Validator / Confirmations.php

Confirmations.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 1.2.4, at app/Modules/Form/Settings/Validator/Confirmations.php

74 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Modules\Form\Settings\Validator;
4
5 use FluentValidator\Validator;
6
7 class Confirmations
8 {
9 /**
10 * Validates confirmations settings data.
11 *
12 * @param array $data
13 *
14 * @return bool
15 */
16 public static function validate($data = [])
17 {
18 // Prepare the validation rules & messages.
19 list($rules, $messages) = static::validations();
20
21 // Make validator instance.
22 $validator = Validator::make($data, $rules, $messages);
23
24 // Add conditional validations if there's any.
25 $validator = static::conditionalValidations($validator);
26
27 // Validate and process response.
28 if ($validator->validate()->fails()) {
29 wp_send_json_error([
30 'errors' => $validator->errors()
31 ], 423);
32 }
33
34 return true;
35 }
36
37 /**
38 * Produce the necessary validation rules and corresponding messages
39 *
40 * @return array
41 */
42 public static function validations()
43 {
44 return [
45 [
46 'redirectTo' => 'required',
47 'customPage' => 'required_if:redirectTo,customPage',
48 'customUrl' => 'required_if:redirectTo,customUrl',
49 ],
50 [
51 'redirectTo.required' => 'The Confirmation Type field is required.',
52 'customPage.required_if' => 'The Page field is required when Confirmation Type is Page.',
53 'customUrl.required_if' => 'The Redirect URL field is required when Confirmation Type is Redirect.',
54 'customUrl.url' => 'The Redirect URL format is invalid.',
55 ]
56 ];
57 }
58
59 /**
60 * Add conditional validations to the validator.
61 *
62 * @param \FluentValidator\Validator $validator
63 *
64 * @return \FluentValidator\Validator
65 */
66 public static function conditionalValidations(Validator $validator)
67 {
68 $validator->sometimes('customUrl', 'url', function ($input) {
69 return $input['redirectTo'] === 'customUrl';
70 });
71
72 return $validator;
73 }
74 }