• Resolved Steven Phan

    (@dayclone)


    Hello,

    I am trying to configure a way so that the email field collected is posted to another page. Could someone point me in a direction of a tutorial or how I would do this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Aurovrata Venet

    (@aurovrata)

    the email field collected is posted to another page

    you can either append the email as url attribute to the page slug, or use a transient field in your option table.

    Thread Starter Steven Phan

    (@dayclone)

    Thank you, I’ve tried inputting a code to attribute it into the url when redirecting but I’m having troubles. The page won’t redirect and I’ve inputted it into the functions.php.

    `//This function prints the JavaScript to the footer
    function add_this_script_footer(){ ?>

    <script type=”text/javascript”>
    document.addEventListener( ‘wpcf7mailsent’, function( event ) {
    if ( ‘16411’ == event.detail.contactFormId ) { // Southland
    location = ‘https://url.com/wp-content/uploads/pdf/success-stories/tech.pdf&#8217;;
    ga(‘send’, ‘event’, ‘Contact Form’, ‘submit’);
    fbq(‘track’, ‘Lead’);
    } else if ( ‘17633’ == event.detail.contactFormId ) { // SurexDirect
    location = ‘https://reputationshielder.com/wp-content/uploads/pdf/success-stories/SurexDirect.pdf&#8217;;
    ga(‘send’, ‘event’, ‘Contact Form’, ‘submit’);
    fbq(‘track’, ‘Lead’);
    } else if ( ‘17634’ == event.detail.contactFormId ) { // GetAssist
    location = ‘https://url.com/wp-content/uploads/pdf/success-stories/GetAssist.pdf&#8217;;
    ga(‘send’, ‘event’, ‘Contact Form’, ‘submit’);
    fbq(‘track’, ‘Lead’);
    } else if ( ‘17655’ == event.detail.contactFormId ) { // Negative Reviews eBook
    location = ‘https://url.com/wp-content/uploads/pdf/ebook/Reviews.pdf&#8217;;
    ga(‘send’, ‘event’, ‘Contact Form’, ‘submit’);
    fbq(‘track’, ‘Lead’);
    } else if ( ‘18180’ == event.detail.contactFormId ) {
    var inputs = event.detail.inputs;
    for ( var i = 0; i < inputs.length; i++ ) {
    if ( ’email’ == inputs[i].name ) {
    var email = inputs[i].value;
    }
    }
    location = ‘https://url.com/Account/Register?email=’+email+&#8217;;
    } else { // Sends submissions on all unaccounted for forms to the third thank you page
    location = ‘https://www.url.com&#8217;;
    ga(‘send’, ‘event’, ‘Contact Form’, ‘submit’);
    fbq(‘track’, ‘Lead’);
    }
    }, false );
    </script>

    <?php }

    add_action(‘wp_footer’, ‘add_this_script_footer’);

    Plugin Author Aurovrata Venet

    (@aurovrata)

    Hi @dayclone, apologies I could not get back to you earlier, got caught up with a new release. The good news, is that I have introduce a simple way to solve this problem in the new version 3.1 which I have just released.

    Place the following in your functions.php file,

    add_filter('cf7_2_post_form_append_output', 'redirect_on_submit', 10, 3);
    function redirect_on_submit($script, $attr, $nonce){
      //$attr cf7 shortcode attributes to check if this is the correct form.
      $url = site_url('/submitted'); //page slug to redirect to.
      $url = add_query_arg( array('cf72post' => $nonce,), $url);
      $url = esc_url($url);
      $script = '<script>'.PHP_EOL;
      $script .= 'document.addEventListener( "wpcf7mailsent", function( event ) {'.PHP_EOL;
      $script .= '  var save = document.getElementsByClassName("cf7_2_post_draft");'.PHP_EOL;
      $script .= '  if(save.length == 0  || "false" === save[0].value){'.PHP_EOL;
      $script .= '    location = "'.$url.'";'.PHP_EOL;
      $script .= '  }'.PHP_EOL;
      $script .= '}, false );'.PHP_EOL;
      $script .= '</script>'.PHP_EOL;
      return $script;
    }

    where you need to change the slug of your page to which you want to redirect.

    Now the submitted form is saved to a post and its ID is stored in a transient field by the plugin. You can access this transient field with the following code in your page template,

    
    if(isset($_GET['cf72post'])){
      $post_id = get_transient($_GET['cf72post']);
      echo 'form submission saved to post:'.$post_id;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Post email to page’ is closed to new replies.