Reputation: 1
I'm trying to alter the status of the Contact Form 7 result after an API call so I can return an error on the front end if required (ie by default this should show a red error under the form, from the ajax response)
I'm using the Forms3rdPartyIntegration plugin, but this just gives me a callback hook where I can then try and change the CF7 output (https://github.com/zaus/forms-3rdparty-integration)
As far as I can see the CF7 status is read only? I can't see a way to stop CF7 just giving a mail_sent_ok status
add_action('Forms3rdPartyIntegration_service', array(&$this, 'service_callback'), 10, 2);
public function service_callback($response, $results) {
$submission = WPCF7_Submission::get_instance();
$cf7 = WPCF7_ContactForm::get_current();
// check for errors (code omitted)
// this is what I am essentially trying to do
// but doesn't work
$submission->status = 'mail_failed'
$cf7->skip_mail = true;
...
}
I'd be grateful if anyone had any pointers on triggering a CF7 fail response.
This appears to be a similar issue wordpress invalidate cf7 after api call
Upvotes: 0
Views: 2666
Reputation: 83
I know this is an old question, but for anyone who encounters this question, I think you are looking for this:
if(your_condition) {
add_filter("wpcf7_ajax_json_echo", function ($response, $result) {
$response["status"] = "mail_sent_ng";
$response["message"] = "Validation errors occurred. Please confirm the fields and submit it again.";
return $response;
});
}
This gives the status mail_sent_ng
instead of mail_ok_sent
.
Also $response["message"]
sets the error/ajax message that is shown to user.
Since you already had $cf7->skip_mail = true
in your code, you have stopped the mail from sending, and with the code above, you have shown the user that there was an error.
You can also use status validation_error
.
Upvotes: 3