• Resolved paze87

    (@paze87)


    Hello @all,

    if a field is outside of a group, the field validation works fine:
    https://cl.ly/5c8007f323c9

    
    function validate_form($form, $args) {
    	$binding_reservation = af_get_field( 'binding_reservation' );
    	if ( empty($binding_reservation) ) {
    		af_add_error( 'binding_reservation', 'Please accept' );
    	}
    }
    add_action( 'af/form/validate/key=form_5cc7111a61557', 'validate_form', 10, 3 );
    

    But if the field is in a group, nothing happens?
    https://cl.ly/94a8019bdf6f

    Is there a sub-field function or anything else?
    Like this => af_get_sub_field( ” );

    BR, Patrick

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

    (@fabianlindfors)

    Hi, Patrick!

    Sorry to say that af_add_error currently doesn’t support sub fields in groups. You might be able to get around this by using the ACF function acf_add_validation_error instead. There is some info in the ACF documentation: https://www.advancedcustomfields.com/resources/acf-validate_save_post/.

    Sorry for the inconvenience!

    Thread Starter paze87

    (@paze87)

    Hey Fabian,
    thank you ?? ! This works:

    
    // ------ Validate => select_appointment ------
    function acfValAppointment( $valid, $value, $field, $input ){
    	
    	// bail early if value is already invalid
    	if( !$valid ) {
    		return $valid;
    	}
    	
    	// load data
    	$appointmentField = get_field('select_appointment');
    
    	if( empty($appointmentField) ) {
    		$valid = 'Bitte w?hlen Sie einen Termin aus!';
    	} 
    	// return
    	return $valid;
    }
    add_filter('acf/validate_value/name=select_appointment', 'acfValAppointment', 10, 4);
    
    

    Another question:

    Is there a option to implement => HoneyPot or Captcha to restrict spam entrys?

    Br and thank you, Patrick

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Validate field in groups not working’ is closed to new replies.