• Resolved anderenbenutzer

    (@anderenbenutzer)


    Hi,
    I’m using acf/validate_value filter to check if a mail address already exists on an acfe form.

    
    

    function my_acf_validate_value_email( $valid, $value, $field, $input ) {

    // Bail early if value is already invalid.
    if( ! $valid ) {
    return $valid;
    }

    if ( isset( $_REQUEST[‘profil’] ) ) {
    $profil = $_REQUEST[‘profil’];
    } // endif

    if ( isset( $_REQUEST[‘user_id’] ) ) {
    $user_id = intval( $_REQUEST[‘user_id’] );
    }

    // Email aus der DB
    $user_data = ( get_userdata( $user_id ) );
    $user_email = $user_data -> user_email;

    if ( $profil == “edit” ) {
    if ( $value == “” || $value == ” ” ) {
    return “E-Mail-Feld darf nicht leer sein”;
    } // endif
    // Eamil nur prüfen, wenn neu ungleich alte Email
    if ( $value != $user_email ) {
    if( email_exists($value) ) {
    return “Diese E-Mail existiert bereits. Verwende bitte eine andere E-Mail.”;
    wp_die();
    } // endif
    } // endif
    } // endif

    if ( $profil == “new” ) {
    if( $value == “” || $value == ” ” ) {
    return “E-Mail-Feld darf nicht leer sein”;
    wp_die();
    } // endif
    if( email_exists($value) ) {
    return “Diese E-Mail existiert bereits. Verwende bitte eine andere E-Mail.”;
    wp_die();
    } // endif
    } // endif

    return $valid;
    }
    add_filter(‘acf/validate_value/key=field_6138824018e44’, ‘my_acf_validate_value_email’, 10, 4); // name=email`

    As return I don’t get an ajax-error message, instead I get the error page. Do I something wrong or is there an issue on acfe form validation?

    thanks in advance

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    You shouldn’t use any wp_die() in the acf/validate_value hook. You only have to return the error message, or return $valid normally if there are none.

    I would recommend to check the ACF documentation, you’ll find some working examples in there.

    Hope it helps!

    Have a nice day!

    Regards.

    Thread Starter anderenbenutzer

    (@anderenbenutzer)

    Hi,
    thanks for your advice.
    I removed the wp_die() functions and found also an error in the code. The error was the reason for the error page output. I quote John Huebner: “When this happens in generally means that there was a php error or warning generated during the validation ajax request. Turn on error debugging and error logging and check your error log.”

    Have a nice day!
    Regards

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    I’m glad to hear it now works as expected!

    Have a nice day!

    Regards.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘acf/validate_value with acfe form’ is closed to new replies.