Last active
March 18, 2021 09:42
-
-
Save wpmudev-sls/8975c5339b997bffadced3fdebcf1b5e to your computer and use it in GitHub Desktop.
[Forminator Pro] - Fix can not sumit on nest required fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: [Forminator Pro] - Fix can not sumit on nest required fields | |
* Description: [Forminator Pro] - Fix can not sumit on nest required fields - 1153408161998285 | |
* Author: Thobk @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org | |
* License: GPLv2 or later | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} elseif ( defined( 'WP_CLI' ) && WP_CLI ) { | |
return; | |
} | |
add_action( 'after_setup_theme', 'wpmudev_forminator_fix_can_not_submit_on_nest_required_fields_func', 100 ); | |
function wpmudev_forminator_fix_can_not_submit_on_nest_required_fields_func() { | |
if ( defined('FORMINATOR_PRO') && class_exists( 'Forminator' ) ) { | |
class WPMUDEV_FM_Fix_Sumit_Error_Required{ | |
private $pseudo_submitted_data; | |
private $custom_form; | |
private $submitted_data; | |
public function __construct(){ | |
add_filter( 'forminator_custom_form_pseudo_submitted_data', array( $this, 'save_submitted_data'), 10, 3 ); | |
add_filter( 'forminator_custom_form_submit_errors', array( $this, 'custom_form_submit_errors' ), 10, 3 ); | |
} | |
public function save_submitted_data( $pseudo_submitted_data, $custom_form, $submitted_data ){ | |
$this->pseudo_submitted_data = $pseudo_submitted_data; | |
$this->custom_form = $custom_form; | |
$this->submitted_data = $submitted_data; | |
return $pseudo_submitted_data; | |
} | |
public function custom_form_submit_errors( $submit_errors, $form_id, $field_data_array){ | |
if( $submit_errors && $this->custom_form ){ | |
$field_forms = forminator_fields_to_array(); | |
foreach( $submit_errors as $error_id => $errors ){ | |
foreach( $errors as $field_id => $msg ){ | |
if( ! isset( $field_data_array[ $field_id ] ) ){ | |
$field_array = $this->custom_form->get_field( $field_id, true ); | |
$field_type = isset( $field_array['type'] ) ? $field_array['type'] : ''; | |
$form_field_obj = isset( $field_forms[ $field_type ] ) ? $field_forms[ $field_type ] : null; | |
if( ! empty( $field_array['conditions'] ) && $form_field_obj ){ | |
if ( $form_field_obj->is_available( $field_array ) && ! $form_field_obj->is_hidden( $field_array, $this->submitted_data, $this->pseudo_submitted_data, $this->custom_form ) ) { | |
unset( $submit_errors[ $error_id ][ $field_id ] ); | |
if( empty( $submit_errors[ $error_id ] ) ){ | |
unset( $submit_errors[ $error_id ] ); | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
return $submit_errors; | |
} | |
} | |
$run = new WPMUDEV_FM_Fix_Sumit_Error_Required; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment