0

I need to send some of the data from my WordPress Contact Form 7 form to an external API. I can do this via Javascript but only want to do so IF and ONLY IF the data validates AND PRIOR TO the mail getting sent. The reason I need to access the external API prior to the email sending is because the API has its own validation that needs to pass and I need to be able to communicate back to the user. So in essence the logic flow needs to be:

  • Validate Contact Form 7
  • Validate external API
  • Send email confirmation

According to their docs, I can perform custom Javascript logic on Contact Form 7 submit OR sent, but not in between which is what I need to do.

From the docs:

http://contactform7.com/additional-settings/

on_sent_ok: "alert('sent ok');"
on_submit: "alert('submit');"

If you set on_sent_ok: followed by a one-line JavaScript code, you can tell the contact form the code that should be performed when the mail is sent successfully. Likewise, with on_submit:, you can tell the code that should be performed when the form submitted regardless of the outcome.

etipaced
  • 125
  • 1
  • 11
  • Does the API access need to be done in JavaScript? Or can it be done in PHP on the server? – Hobo Oct 07 '16 at 02:42
  • use "wpcf7_before_send_mail" hook to check validations before mail send – Sanoj Sharma Oct 07 '16 at 03:52
  • http://stackoverflow.com/questions/30533216/contact-form-7-use-hook-created-using-wpcf7-before-send-mail-for-only-one-conta – Sanoj Sharma Oct 07 '16 at 03:53
  • Thank you for the assistance. However, I decided to forego the usage of Contact Form 7 altogether. I'm now using the jQuery Validation library in tandem with the 3rd party API to handle my form. I'll write custom PHP code to do the back end processing. – etipaced Oct 07 '16 at 16:35

0 Answers0