PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Dynamically populate second address on multi-page form?

  1. bleckett
    Member

    Is there an easy way to do this?

    I have a (USA) address block on page 1 of a multi-page form (home address - Field ID 3).
    I also have an identical address block on page 2 of the form (billing address - Field ID 7).
    Above the address I have a check box that says "Use Home Address".

    Is there a simple way to dynamically populate the second address (Field ID 7) with all the data from the first (Field ID 3) address when the user clicks on the "Use Home Address" checkbox?

    Posted 12 years ago on Saturday September 10, 2011 | Permalink
  2. @bleckett - I am no programming master BUT we were able to accomplish pre-populating field values from another form on demand using simple jQuery and the following steps:.

    1. Set the confirmation action of the page 1 form to redirect and select "Pass Field Data Via Query String".
    2. Build the appropriate query string as shown in the example. For example: firstname={First Name::1}&lastname={Last Name::2}&address1={Address 1::3}&address2={Address 2::4}&city={City:5}&state={State::8}&zip={Zip::6}&email={Email::9}&phone={Phone::7}&birthdate={Birthdate::10}

    3. setup hidden fields on the page 2 form for each of the page one variable being passed and in the advanced tab of each hidden field, check "Allow field to be populated dynamically" and set the parameter to the name of the appropriate field variable being passed from page 1.

    4. In the header (header.php in WP), place jQuery code, similar to the following, before the </head> tag (change the field ID's and GET values to match yours):

    [js]
    	jQuery(document).ready(function() {
    
    			jQuery("#choice_1_1").click(function(){
    				if (jQuery("#choice_1_1").is(":checked")){
    					jQuery("#input_2_7").val("<?php echo $_GET['address1']; ?>");
    					jQuery("#input_2_8").val("<?php echo $_GET['address2']; ?>");
    					jQuery("#input_2_9").val("<?php echo $_GET['city']; ?>");
    					jQuery("#input_2_10").val("<?php echo $_GET['state']; ?>");
    					jQuery("#input_2_11").val("<?php echo $_GET['zip']; ?>");
    				}else{
    					jQuery("#input_2_7").val("");
    					jQuery("#input_2_8").val("");
    					jQuery("#input_2_9").val("");
    					jQuery("#input_2_10").val("");
    					jQuery("#input_2_11").val("");
    				}
    			});
    
    	});

    Hope this helps!

    Posted 12 years ago on Saturday September 10, 2011 | Permalink
  3. Here is the jQuery code again:

    http://www.pastie.org/2514670

    Posted 12 years ago on Saturday September 10, 2011 | Permalink
  4. bleckett
    Member

    Thanks for the info... I'm going to play with this.

    Posted 12 years ago on Sunday September 11, 2011 | Permalink
  5. Unfortunately this solution is not working. The GET in jQuery means that you get that data out of the url. But this data is not presented in the url.

    Has anybody got it to work yet?

    Posted 12 years ago on Monday September 19, 2011 | Permalink
  6. Have you changed all the references from $_GET to $_POST to see if that works?

    Posted 12 years ago on Tuesday September 20, 2011 | Permalink
  7. I've got it working now. My address and billing address are now on the same page and I'm not using hidden fields.

    The solution I used is this tutorial: http://www.encaffeinated.com/articles/view/copying_billing_and_shipping_address_information_with_jquery/

    Posted 12 years ago on Tuesday September 20, 2011 | Permalink
  8. Very good. Thanks for posting the link.

    Posted 12 years ago on Wednesday September 21, 2011 | Permalink

This topic has been resolved and has been closed to new replies.