• i hook into via “wpcf7_mail_sent” and do an curl api call to an external website.

    what i want to achieve now is, to invalidate the wpcf7 if the api call returns errors e.g. because of the api server being down or api validation errors.

    is there a way to invalidate the wpcf7 and set the complete form’s error message (the one below the complete form), so that the user can not submit the form?
    maybe via another hook like “wpcf7_submit”?

    (i don’t mean to invalidate fields and set their error messages like on https://contactform7.com/2015/03/28/custom-validation/)

    best regards

    https://www.ads-software.com/plugins/contact-form-7/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi ageibert,

    I’ve used the wpcf7_validate_api for this, first create a filter:
    add_filter(‘wpcf7_validate_api’, ‘validate_api’, 20, 2);
    now in this block you can get the values using:

    $submission = WPCF7_Submission::get_instance();
    $wpcf7_data = $submission->get_posted_data();

    you can then call you’re api (presumably with curl) and invalidate as follows (presume $success is from the api call)

    if (!$success) {
    $result->invalidate($tag, ‘api call_failed (statuscode:’ . $statuscode . ‘).’ . $statusdesc[0]);
    }

    and finally

    return $result

    hope this helps

    Thread Starter ageibert

    (@ageibert)

    hi @craigstanfield and thanks for the response.
    one question:
    where does the $result variable come from?
    or did you mean $submission->invalidate()?

    best regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘api call and invalidate wpcf7’ is closed to new replies.