• Resolved vratnieks

    (@vratnieks)


    Hi,

    When using the action wpcf7_before_send_mail, what is the correct way of telling CF7 to not post (or email) the form for whatever reason e.g. an API call failed.

    I’ve tried so many ways but none seem to work. Assume that all fields validate so I don’t want to invalidate using wpcf7_validate. I would just like to stop cf7 and return to the form with an error message and field values still in place.

    Cheers, Vic

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

    (@takayukister)

    The second argument is for the purpose. To abort the submission, change $abort to true like the following:

    add_action( 'wpcf7_before_send_mail',
      function( $contact_form, &$abort, $submission ) {
        $abort = true;
      },
      10, 3
    );
    Thread Starter vratnieks

    (@vratnieks)

    Takayuki, thank you. It’s a real treat getting a reply from the developer himself! You’re a legend with CF7, thank you! It’s truly a great plugin and I’ve used it on many sites.

    I was sooooo close. I actually tried that based on this thread I found (below). But I realise I forgot to set the number of parameters to the function (ie. 3) and that was causing an error. I was so tired I couldn’t see it so in the end posted my question.

    https://stackoverflow.com/questions/36774134/wordpress-invalidate-cf7-after-api-call/49243202

    Where is the best documented reference to hooks for CF7 with examples. hookr.io is very high level and doesn’t give any explanation of what each are for or examples.

    e.g. wpcf7_form_novalidate

    What is it for and how should it be used?

    Thanks again!

    Cheers, Vic

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘What is the right way of stopping CF7 from posting using wpcf7_before_send_mail’ is closed to new replies.