• Resolved jdesj043

    (@jdesj043)


    Hello,

    I want my form to prevent a new entry from being created if the email address entered has been entered before but I still want to redirect to another page. I’m assuming it has something to do with the validation hook but can’t figure out how to stop the form submission without af_add_error().

    Just as a general note—it would be great to see the documentation updated with more information. It seems to lack any instruction on how to display entry information on the success page in the PHP template.

    Thanks!

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

    (@fabianlindfors)

    Hi!

    If you want to stop the form and redirect before an entry is created you can use the “af/form/submission” action with a priority of 0. You also need to include an exit after redirect.

    
    function check_email_exists() {
      $email = af_get_field( 'EMAIL_FIELD' );
      $email_exists = // ... add code to check if email exists.
    
      if ( $email_exists ) {
        wp_redirect( 'REDIRECT_URL' );
        exit;
      }
    }
    add_action( 'af/form/sumbission/key=FORM_KEY', 'check_email_exists', 0, 0 );
    

    This will run before entry creation and will stop it thanks to the exit statement.

    Please give it a test!

    Plugin Author fabianlindfors

    (@fabianlindfors)

    Hi! I’ll close this for now. Please re-open if you need more help. ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Prevent entry creation’ is closed to new replies.