Search code examples
phpwordpresscontact-form-7

Using Contact Form 7 wpcf7_feedback_response to output html in the response?


I am trying to output a hidden iFrame that will load in the AJAX response after submitting the form. It just outputs it as a string currently. Is this possible to do any other way?

add_filter('wpcf7_feedback_response', function($response, $result) {
    $iframe_url = "https://software.loks.com/handler239" . "email=" . urlencode($_POST['email']) . "&company=" . urlencode($_POST['company']) . "&phone=" . urlencode($_POST['phone']);

    $iframe_html = '<iframe src="' . $iframe_url . '" width="1" height="1" style="display:none;"></iframe>';
    $response['message'] = $iframe_html;

    return $response;
}, 10, 2);

Solution

  • This is an ongoing issue with CF7 plugin and its author simply ignores requests to enable richer response messages citing security concerns, which albeit has some merit, should really be left to the website admin to decide how to configure/customise their site.

    You can see multiple requests/issues raised on the GitHub plugin repo, here, here and here, which have all been closed and tagged as invalid, and if you raise a concern more than once you get blocked from the author :(. The author closed this door with this update.

    In the above linked issues, you will find multiple comments with multiple suggestions as work arounds, alternatively, I maintain a CF7 plugin extension, The Smart-grid layout for CF7, which allows you to publish HTML rich messages,

    add_filter( 'cf7sg_submission_response', 'html_response', 10, 4 );
    function html_response( $msg, $status, $data, $cf7key ) {
      if( 'my-form' === $cf7key && 'mail_sent' === $status){
          $msg= 'Hello click <a href="#here">here</a>';
      }
      return $msg;
    }