PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.2.3
JetFormBuilder — Dynamic Blocks Form Builder v3.2.3
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 2 years ago is-user-email-unique.php 2 years ago is-user-login-unique.php 2 years ago rest-controller.php 2 years ago rest-validation-endpoint.php 2 years ago validation-callbacks.php 2 years ago
rest-validation-endpoint.php
101 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Blocks\Ssr_Validation;
5
6 use Jet_Form_Builder\Blocks\Block_Helper;
7 use Jet_Form_Builder\Blocks\Validation;
8 use Jet_Form_Builder\Classes\Arrayable\Array_Tools;
9 use Jet_Form_Builder\Exceptions\Repository_Exception;
10 use Jet_Form_Builder\Exceptions\Silence_Exception;
11 use Jet_Form_Builder\Request\Exceptions\Plain_Value_Exception;
12 use JFB_Modules\Block_Parsers\Field_Data_Parser;
13 use JFB_Modules\Block_Parsers\Parser_Context;
14 use Jet_Form_Builder\Request\Request_Tools;
15 use JFB_Components\Rest_Api;
16
17
18 // If this file is called directly, abort.
19 if ( ! defined( 'WPINC' ) ) {
20 die;
21 }
22
23 class Rest_Validation_Endpoint extends Rest_Api\Rest_Api_Endpoint_Base {
24
25 const FIELD_KEY = '_jfb_validation_path';
26 const RULE_INDEX_KEY = '_jfb_validation_rule_index';
27
28 public static function get_rest_base() {
29 return 'validate-field';
30 }
31
32 public static function get_methods() {
33 return \WP_REST_Server::CREATABLE;
34 }
35
36 public function run_callback( \WP_REST_Request $request ) {
37 $body = $request->get_body_params();
38
39 try {
40 $parser = $this->get_parser( $request );
41 } catch ( Silence_Exception $exception ) {
42 return new \WP_REST_Response(
43 array(
44 'message' => __( 'Unresolved parser for field', 'jet-form-builder' ),
45 ),
46 400
47 );
48 }
49
50 $validation = $parser->get_setting( 'validation' );
51
52 $callback = Array_Tools::get(
53 $validation,
54 array( 'rules', $body[ self::RULE_INDEX_KEY ], 'value' )
55 );
56
57 if ( ! $parser->get_value() || ! $callback ) {
58 return new \WP_REST_Response(
59 array(
60 'message' => __( 'Field value or callback is empty', 'jet-form-builder' ),
61 ),
62 400
63 );
64 }
65
66 $result = Validation::instance()->callbacks->validate( $parser, $callback );
67
68 return new \WP_REST_Response(
69 array(
70 'result' => $result,
71 ),
72 200
73 );
74 }
75
76 /**
77 * @param \WP_REST_Request $request
78 *
79 * @return Field_Data_Parser
80 * @throws Plain_Value_Exception
81 * @throws Repository_Exception
82 */
83 protected function get_parser( \WP_REST_Request $request ): Field_Data_Parser {
84 $body = $request->get_body_params();
85 $path = $body[ self::FIELD_KEY ] ?? false;
86 $form_id = $body[ jet_fb_handler()->form_key ] ?? false;
87
88 jet_fb_handler()->set_form_id( $form_id );
89
90 jet_fb_context()->set_request( $body );
91 jet_fb_context()->set_files( Request_Tools::get_files( $request->get_file_params() ) );
92
93 // set fields with request
94 jet_fb_context()->apply(
95 Block_Helper::get_blocks_by_post( $form_id )
96 );
97
98 return jet_fb_context()->resolve_parser( $path );
99 }
100 }
101