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.