PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.0.8
JetFormBuilder — Dynamic Blocks Form Builder v3.0.8
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / blocks / ssr-validation / rest-validation-endpoint.php
jetformbuilder / includes / blocks / ssr-validation Last commit date
base-validation-callback.php 3 years ago is-user-email-unique.php 3 years ago is-user-login-unique.php 3 years ago rest-controller.php 3 years ago rest-validation-endpoint.php 3 years ago validation-callbacks.php 3 years ago
rest-validation-endpoint.php
113 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Blocks\Ssr_Validation;
5
6
7 use Jet_Form_Builder\Blocks\Validation;
8 use Jet_Form_Builder\Exceptions\Parse_Exception;
9 use Jet_Form_Builder\Request\Parser_Context;
10 use Jet_Form_Builder\Request\Request_Tools;
11 use Jet_Form_Builder\Rest_Api\Rest_Api_Endpoint_Base;
12
13 class Rest_Validation_Endpoint extends Rest_Api_Endpoint_Base {
14
15 const FIELD_KEY = '_jfb_validation_field';
16 const CALLBACK_KEY = '_jfb_validation_callback';
17 const PARENT_KEY = '_jfb_validation_parent';
18 const ROOT_KEY = '_jfb_validation_root';
19
20 public static function get_rest_base() {
21 return 'validate-field';
22 }
23
24 public static function get_methods() {
25 return \WP_REST_Server::CREATABLE;
26 }
27
28 public function run_callback( \WP_REST_Request $request ) {
29 $body = $request->get_body_params();
30
31 list(
32 $value,
33 $context,
34 $name,
35 $parent_name
36 ) = $this->get_validation_context( $request );
37
38 $context->set_raw_field(
39 array(
40 'blockName' => 'some-field',
41 'attrs' => array(
42 'name' => $name,
43 'parent_name' => $parent_name,
44 )
45 )
46 );
47
48 $callback = $body[ self::CALLBACK_KEY ] ?? false;
49
50 if ( ! $value || ! $callback ) {
51 return new \WP_REST_Response(
52 array(
53 'message' => __( 'Field value or callback is empty', 'jet-form-builder' ),
54 ),
55 400
56 );
57 }
58
59 $result = Validation::instance()->callbacks->validate(
60 $value,
61 $callback,
62 $context
63 );
64
65 return new \WP_REST_Response(
66 array(
67 'result' => $result
68 ),
69 200
70 );
71 }
72
73 /**
74 * @param \WP_REST_Request $request
75 *
76 * @return array<mixed|Parser_Context>
77 */
78 protected function get_validation_context( \WP_REST_Request $request ): array {
79 $body = $request->get_body_params();
80 $context = new Parser_Context();
81 $parent_name = $body[ self::PARENT_KEY ] ?? false;
82 $field_name = $body[ self::FIELD_KEY ] ?? false;
83
84 if ( ! $parent_name || empty( $body[ $parent_name ] ) ) {
85 jet_fb_handler()->set_form_id( $body[ jet_fb_handler()->form_key ] ?? false );
86
87 $files = Request_Tools::get_files( $request->get_file_params() );
88
89 jet_fb_request_handler()->set_raw_request( $body );
90 jet_fb_request_handler()->set_raw_files( $files );
91
92 $context->set_request_context( $body );
93 $context->set_files_context( $files );
94
95 $value = $body[ $field_name ] ?? false;
96
97 return array( $value, $context, $field_name, $parent_name );
98 }
99
100 // this field inside repeater row
101
102 $row_values = array_values( $body[ $parent_name ] )[0];
103 $all_values = $body[ self::ROOT_KEY ] ?? array();
104
105 $context->set_request_context( $row_values );
106 jet_fb_request_handler()->set_raw_request( $all_values );
107 jet_fb_handler()->set_form_id( $all_values[ jet_fb_handler()->form_key ] ?? false );
108
109 $value = $row_values[ $field_name ] ?? false;
110
111 return array( $value, $context, $field_name, $parent_name );
112 }
113 }