Support

Account

Home Forums Front-end Issues acf form validation only on certain page Reply To: acf form validation only on certain page

  • Hi @sami616

    Could you please tell me if this “registration template” is on front end or back end?

    If it is on the front end, I think you can add a hidden input on your form to mark it as a registration page. Maybe something like this:

    acf_form(array(
        'html_after_fields' => '<input type="hidden" name="acf[register]" value="true"/>',
    ));

    After that, you can check this hidden input using the $_POST variable. It should be something like this:

    add_filter('acf/validate_value/name=sr_email', 'my_acf_validate_email', 10, 4);
    function my_acf_validate_email( $valid, $value, $field, $input ){
    	
    	if( !$valid ) {
    		return $valid;
    	}
        
    	if(($_POST['acf']['register'] == 'true') && email_exists($value)){
    		$valid = 'Email already in use';
    	}
    
    	return $valid;
    }

    I hope this helps.