简体   繁体   中英

Server Side Validation with Flamingo and Contact Form 7

I have the last WordPress site, with the last contact form 7 and flamingo plugins installed.

It's a simple form, with an email field and a message field.

I want to make a query to the database to check if the email had already sent a previous message into my site.

Is this possible?.

I'm trying to create a PHP file that makes the query into the database, and I call that file with ajax after the form is submitted.

Is it a good idea?

Do you mean this:

add_filter( 'wpcf7_validate', 'email_already_in_db', 10, 2 );

function email_already_in_db ( $result, $tags ) {
    // retrieve the posted email
    $form  = WPCF7_Submission::get_instance();
    $email = $form->get_posted_data('your-email');

    // if already in database, invalidate
    if( email_exists( $email ) ) // email_exists is a WP function
        $result->invalidate('your-email', 'Your email exists in our database');

    // return the filtered value
    return $result;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM