advancedforms / advanced-forms

WordPress plugin to create forms using Advanced Custom Fields
75 stars 14 forks source link

Prevent entry creation doesnt work #75

Closed ghost closed 4 years ago

ghost commented 4 years ago

I read your answer to this question: https://wordpress.org/support/topic/prevent-entry-creation/

function check_email_exists() {
    $email = af_get_field( 'email' );

    // args
    $args  = array(
        'post_type'   => 'af_entry',
        'meta_query' => array(
            array(
                'key' => 'email',
                'value' => $email,
                'compare' => '=',
            )
        ),
    );
    $query = new WP_Query( $args );
    if( $query->have_posts() ){
        $email_exists = true;
    } else {
        $email_exists = false;
    }

    if ( $email_exists ) {
        wp_redirect( '/thanks/' );
        exit;
    }
}
add_action( 'af/form/submission/key=form_MYKEY', 'check_email_exists', 0, 0 );

I get redirected but the entry is created anyway :(

ghost commented 4 years ago

is this a good place to report issues? it has been almost two weeks and no follow up?

fabianlindfors commented 4 years ago

Sorry. This and the WordPress forum are good places to seek support. Unfortunately I can only offer support as time allows for the free version. I've been pretty swamped the past couple of weeks.

Based on your code I can't see anything obviously wrong. Could you try adding wp_die( 'TEST' ); before the exit; line and see if you get an error message after submit? Thank you.