How to transfer values ​​from one form of contact form 7 to another in Wordpress?

I have a website that has 2 forms - short form and long form. If you look at http://dforbesinsuranceagency.com , you will see a short form next to the mast photo. The long form is at http://dforbesinsuranceagency.com/request-free-insurance-quotes/

When the user clicks "Submit" in short form, he pushes them onto a page of long form, so this part works fine. The part that gives me the opportunity is that I need the values ​​entered in the short form fields. Name, surname, email address and telephone number are transferred to their equivalent fields in long form.

How to do it?

This is how I redirect the short form to the long form (I added it to the Advanced Settings section for the short form):

on_sent_ok: "location = 'http://dforbesinsuranceagency.com//request-free-insurance-quotes';" 

Any help would be appreciated.

+7
source share
2 answers

Hack, hack, hack, hack hack ... Without suggesting “do not use the constructor of forms”, I don’t think there is an elegant solution - you cannot use the other suggested PHP method without changing the plugin (and it can be a worm). I suggest a Javascript solution, but there are some caveats (below):

 jQuery(document).ready(function($){ $('#quick-quote form:first').submit(function(){ var foo = {}; $(this).find('input[type=text], select').each(function(){ foo[$(this).attr('name')] = $(this).val(); }); document.cookie = 'formData='+JSON.stringify(foo); }); var ff = $('#container form:first'); if(ff.length){ var data = $.parseJSON( document.cookie.match('(^|;) ?formData=([^;]*)(;|$)')[2] ); if(data){ for(var name in data){ ff.find('input[name='+name+'], select[name='+name+']').val(data[name]); } } } }); 

Basically it will be: when sending, save the mini-form parameters in a cookie . When the page loads, it will search for the form in the main part of the page and apply any stored cookie data.

Notes

  • JQuery selectors are intentionally ambiguous in order to avoid any future changes in your admin panel / plugin that are likely to be screwed with form identifiers (thus violating the script).
  • I'm not talking about field / option field names - for example, the selection field in the mini-form is called insurance-type , however the correspondence field in the main form is called ins-type - which you will have so that they have the same name .
  • This also applies to the values ​​of the selection fields - if there is no corresponding value, it will be ignored (for example, some of your values ​​in the main form have & raquo; » characters in front (and therefore do not match).
+7
source

try it.

set the action of our first form to a php file named xyz.php

 <form method="post" action="xyz.php"> <input type="text" name="name"> <input type="text" name="email_address"> <input type="submit" value="Go To Step 2"> </form> 

the xyz.php file will create a new form for you, which in this case will be your second form (large). Set the action of the form as needed. your xyz.php code will look something like this.

 <form method="post" action="form3.php"> <input type="text" name="name" value="<?php echo $_POST['name']; ?>"> <input type="text" name="email_address" value="<?php echo $_POST['email_address']; ?>"> <input type="radio" group="membership_type" value="Free"> <input type="radio" group="membership_type" value="Normal"> <input type="radio" group="membership_type" value="Deluxe"> <input type="checkbox" name="terms_and_conditions"> <input type="submit" value="Go To Step 3"> </form> 

where the input fields of the first form will already be filled with data specified by the user in the first form.

You can create the first form yourself and let the contact form create a second form to provide default values ​​using the method above.

Hope this helps!

+2
source

All Articles