ajax-validation-handler.php
1 year ago
self-validation-handler.php
1 year ago
validation-handler.php
4 months ago
ajax-validation-handler.php
38 lines
| 1 | <?php |
| 2 | namespace JFB_Modules\Validation\Handlers; |
| 3 | |
| 4 | use JFB_Modules\Validation\Handlers\Validation_Handler; |
| 5 | |
| 6 | // If this file is called directly, abort. |
| 7 | if ( ! defined( 'WPINC' ) ) { |
| 8 | die; |
| 9 | } |
| 10 | |
| 11 | class Ajax_Validation_Handler { |
| 12 | public function __construct() { |
| 13 | add_action( 'wp_ajax_jet_fb_ssr_validation_ajax', array( $this, 'jet_fb_ssr_validation_ajax' ) ); |
| 14 | add_action( 'wp_ajax_nopriv_jet_fb_ssr_validation_ajax', array( $this, 'jet_fb_ssr_validation_ajax' ) ); |
| 15 | } |
| 16 | public function jet_fb_ssr_validation_ajax() { |
| 17 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 18 | if ( ! isset( $_POST['data'] ) ) { |
| 19 | wp_send_json_error( array( 'message' => 'No data provided' ) ); |
| 20 | } |
| 21 | |
| 22 | // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing |
| 23 | $body = json_decode( stripslashes( $_POST['data'] ), true ); |
| 24 | |
| 25 | foreach ( $body as $key => $value ) { |
| 26 | if ( strpos( $key, '[]' ) !== false ) { |
| 27 | unset( $body[ $key ] ); |
| 28 | $new_key = str_replace( '[]', '', $key ); |
| 29 | $body[ $new_key ] = is_array( $value ) ? $value : array( $value ); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | $result = Validation_Handler::validate( $body ); |
| 34 | |
| 35 | wp_send_json( $result ); |
| 36 | } |
| 37 | } |
| 38 |