PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.2
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.2
6.2.14 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 All 196 releases
fluentform / app / Modules / Form / Settings / Validator / Confirmations.php

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

75 lines 2.2 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 FluentForm\Framework\Validator\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 = wpFluentForm('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 ], 422);
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.', 'fluentform'),
52 'customPage.required_if' => __('The Page field is required when Confirmation Type is Page.', 'fluentform'),
53 'customUrl.required_if' => __('The Redirect URL field is required when Confirmation Type is Redirect.', 'fluentform'),
54 'customUrl.required' => __('The Redirect URL format is invalid.', 'fluentform'),
55 ],
56 ];
57 }
58
59 /**
60 * Add conditional validations to the validator.
61 *
62 * @param \FluentForm\Framework\Validator\Validator $validator
63 *
64 * @return \FluentForm\Framework\Validator\Validator
65 */
66 public static function conditionalValidations(Validator $validator)
67 {
68 $validator->sometimes('customUrl', 'required', function ($input) {
69 return 'customUrl' === $input['redirectTo'];
70 });
71
72 return $validator;
73 }
74 }
75