• Hi,

    I use the 3rd party integration plugin to send the form data to a self-coded php script. If all data is ok, it works as expected. I have the following scenario:

    • 1. The user fills in the form -> OK
    • 2. The data will be validated by wpcf7 -> OK
    • 3. The php-Script echoes “success” on success or nothing on failure. -> OK
    • 4. wpcf7 sends the standard email
    • 5. The contact form redirects to a “Thank you and next steps” site.

    My problem is that regardless whether my script returns success or nothing, wpcf7
    – sends the email
    – redirects to the next site

    This is a big problem because the user will think that the form was submitted, although the script returned an error.

    My settings of the plugin are:
    Success condition: success
    Failure Message: Es ist ein Fehler aufgetreten.

    How can I solve this problem?

    https://wordpress.org/plugins/forms-3rdparty-integration/

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

    (@zaus)

    So it’s supposed to update the CF7 form in this case, specifically by “setting a bad message”, but that’s just to add text to the CF7 results. You can use the same hook, with a later priority, to further affect the CF7 $form object and prevent it from sending.

    I’m not entirely sure how to do that; you used to be able to modify a property of the $form that would prevent it from mailing, but CF7 has changed since I last looked so I’m not sure which hook/property/method to use. I think in your ...remote_failure hook you could add another hook to wpcf7_skip_mail that just returns false.

    ifame

    (@ifame)

    Hi zaus,
    I have a similar issue as this one. When my 3rd party return an error response, I need to be able to skip sending email and stop the redirection to the thank-you page. My implementation is below but it’s not working. Could you please review and let me know if you see anything wrong with it. Thanks!

    My response has a json string in the body and an 400 error code in the response as following:

    [body] => {“status”:”error”, “response”:{“error message”,”error.header”:”There was a problem. Please check the errors below:”}}
    [response] => Array
    (
    [code] => 400
    [message] => Bad Request
    )
    I tried your suggestion of the filter and action as below but neither one works, could you take a look and see if I may have done something incorrectly:
    ---Using filter to process the error status from the body ---
    class MyPlugin {
    public function MyPlugin() {
    add_filter('Forms3rdPartyIntegration_service', array(&$this, 'adjust_response'), 10, 2);
    }
    public function adjust_response($body, $refs) {
    $response_array = json_decode($body);
    try{
    if( false !== strpos($response_array->status, 'error') ) :
    {$refs['message'] = 'Error message';
    add_filter('wpcf7_before_send_mail', 'wpcf7_custom_form_action_url');}
    else:
    $refs['message'] = 'Success message';
    endif;
    } catch(Exception $ex){
    $refs['errors'] = array($ex->getMessage());
    }
    }
    }
    new MyPlugin();

    ---Using action to process response code from the response ---
    function service1_action_callback($response, $results){
    try {
    if( false !== strpos($response['code'], '400') ) {
    $results['message'] = 'Error message';
    add_filter('wpcf7_before_send_mail', 'wpcf7_custom_form_action_url');
    } else {
    $results['message'] = 'Success message';
    }
    } catch(Exception $ex){
    $results['errors'] = array($ex->getMessage());
    }
    }
    add_action('Forms3rdPartyIntegration_service_a0', array(&$this, 'service1_action_callback'), 10, 2);

    --- for skipping email, I tried to implement the following, but it did not seem to work either - please take a look to see if you see anything wrong with it.

    The filter to skip email is added to your function after processing the error response:
    add_filter('wpcf7_before_send_mail', 'wpcf7_custom_form_action_url');
    The function for this filter is:
    function wpcf7_custom_form_action_url( $form) { $submission = WPCF7_Submission::get_instance();
    $submission->skip_mail = true;
    }

    In contact form 7 submission.php, I changed the $skip-mail to public:
    public $skip_mail = false;

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Email and redirection after FAILED submission’ is closed to new replies.