Support

Account

Home Forums Backend Issues (wp-admin) Bypass required fields

Solving

Bypass required fields

  • Hello,
    through the development of the new website I would like to turn off required validation for all fields. I was able to turn off the required flag when the field is printed:

    
    add_filter( 'acf/get_fields', 'turn_of_require' );
    function turn_of_require( $fields ) {
    	foreach ( $fields as &$field ) {
    		$field['required'] = 0;
    	}
    
    	return $fields;
    }
    

    This removes the red star, etc. Unfortunately, the validation script does not get the information about the change and it thinks that fields are still required.

    I know that I could turn off all validation rules via action validate_save_post, but it turns off all rules. I would like to turn off only the required validation.

    Is there any possibility how to do that?

  • You need to edit the field group and edit the field to turn off required.

  • Thanks for your respond. I know about this possibility.

    My problem is somehow different. Those fields are provided by another plugin which I dont want to change because any update would restore the require flag.

    So I am searching for some method which helps me to turn of required flag without changing the register method of the field.

  • You will need to use the acf/load_field hook for each field.

  • Hello, a bit of an old post, but I am facing the same issue. I am running the function using ‘load_field’ and although the field is set as ‘not required’ and this is reflected on the output html, after submitting the form I can still see an error.

    
    function acf_classified_date_required_change( $field ) {
      	$field['required'] = false;
    	return $field;
    }
    add_filter('acf/load_field/name=classified_date', 'acf_classified_date_required_change');
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.