• Resolved Shasta

    (@shastaw)


    I’m trying to set up a validation filter to use a text field as though it were a weak password checker. (Don’t ask — client wants it.)

    I have this field in a form:

    <label>Passcode (required)
    [text* the-passcode]</label>

    and I have this function in my functions.php:
    //—————————————-
    add_filter( ‘wpcf7_validate_text*’, ‘custom_passcode’, 20, 2 );

    function custom_passcode( $result, $tag ) {
    if ( ‘the-passcode’ == $tag->name ) {
    $the-passcode = isset( $_POST[‘the-passcode’] ) ? trim( $_POST[‘the-passcode’] ) : ”;

    if ( $the-passcode != ‘test-passcode’ ) {
    $result->invalidate( $tag, “You have the wrong passcode.” );
    }
    }

    return $result;
    }
    //—————-
    I’ve tried debugging by putting a result->invalidate immediately on entering the function, then returning. That SHOULD have caused the field to fail validation no matter what I put in, but it didn’t, which suggests that the function isn’t getting fired at all.

    Any ideas? I’m using this as a model: https://contactform7.com/2015/03/28/custom-validation/ It’s three years old — is it deprecated? I haven’t found something newer.

    The page I need help with: [log in to see the link]

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

    (@takayukister)

    if ( $the-passcode != 'test-passcode' ) {

    Hyphen (-) isn’t allowed in a variable name, I think.

    https://php.net/manual/en/language.variables.basics.php

    Thread Starter Shasta

    (@shastaw)

    How embarrassing! You’re totally right — it didn’t jump out and when trying to return at the top of the function failed, I got focussed on the idea that the filter wasn’t getting hooked correctly.

    Which it wasn’t, because the function wasn’t compiling at all. Doh.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Validation by filter failing’ is closed to new replies.