Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Razvan Mocanu

    (@razvanmo-1)

    Hi,

    You can use filter on the checking of the required fields.
    There you can add a condition for the “maybe required” field so that it takes into account the value from the decisive field.
    The hook to be used depends on the type of field that is hidden.

    For example, for the field of type Input:

    /* handle field validation */
    function wppbc_check_input_value( $message, $field, $request_data, $form_location ){
    	remove_filter('wppb_check_form_field_input', 'wppb_check_input_value', 10);
    	if( $field['field'] == 'Input' ){
    		if( $field['required'] == 'Yes' ){
    			if( !($field['meta-name'] == "maybe_hidden_custom_field" && $request_data['decisive_field'] == "Make fields below unrequired")) {
    				if ((isset($request_data[wppb_handle_meta_name($field['meta-name'])]) && (trim($request_data[wppb_handle_meta_name($field['meta-name'])]) == '')) || !isset($request_data[wppb_handle_meta_name($field['meta-name'])])) {
    					return wppb_required_field_error($field["field-title"]);
    				}
    			}
    		}
    	}
    
    	return $message;
    }
    add_filter( 'wppb_check_form_field_input', 'wppbc_check_input_value', 5, 4 );

    The function returns a special error message, if the field is required.
    The meta-names of the fields are maybe_hidden_custom_field and decisive_field.

    Thread Starter kkmachado

    (@kkmachado)

    Hi there!

    I’m going to try it.

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Do not validate hidden required fields’ is closed to new replies.