TechieInprogress
TechieInprogress

Reputation: 33

How I can get the values from contact form 7 and prefill it in another page by adding the parameter in the URL of the new page?

As of now, I have tried doing this

  1. In the contact form, under form tab I have added these lines-
<label>
    [email* your-email default:get id:textarea placeholder "Email address"] </label>

<div style="text-align: center;">[submit id:button "Get started now"]</div>
  1. in functions.php file I have added following lines
add_action( 'wp_footer', ’redirect_to_new page’);
 
     function ’redirect_to_new page() {
     ?>
     <script type="text/javascript">
     document.addEventListener( 'wpcf7mailsent', function( event ) {
         If ( '2023' == event.detail.contactFormId ) {
             location = 'https://app.techinme.com/#/registration?email=[your-email]’;
     }
     }, false );
     </script>
     <?PHP
     }

when the user clicks on submit button on the form they are directed to the new page but I am unable to populate the email ID in the new form present in the new page. Can someone please guide me further?

Cheers!

Upvotes: 0

Views: 1068

Answers (1)

mikerojas
mikerojas

Reputation: 2338

This is not tested but should get you going in the right direction.... Below I updated your code to grab the email from the form and append it to the location url:

<?php
add_action( 'wp_footer', 'redirect_to_new_page');
function redirect_to_new_page() {
?>
  <script type="text/javascript">
    document.addEventListener( 'wpcf7mailsent', function( event ) {
      if ( '2023' == event.detail.contactFormId ) {

        // get email
        var email = event.detail.inputs.filter(function(item){
          return item.name === 'your-email';
        })[0].value;

        location = 'https://app.techinme.com/#/registration?email=' + email;
      }
    }, false );
  </script>
<?php
}

Upvotes: 2

Related Questions