Forums

Populate form fields automatically

LandShark 05 Mar, 2012
Hello,
I have a form that submits to a confirmation page. On the form there is a shipping address and billing address. If the user chooses not to enter a shipping address, I want to automatically populate it with the billing info that the user has entered. I want this to happen when the user clicks the submit button so that the data will be present on the confirmation page.

My question is, what is the best way to do this? With a custom code action in the onSubmit area using php? Or with a LoadJS action in the onSubmit area using javascript? I want to populate the actual form values for the shipping address because down the line I will be submitting this info to Paypal using those form values.

Thanks in advance for any help!
GreyHead 06 Mar, 2012
Hi LandShark ,

The simplest way to do it is with PHP after the form is submitted. The only advantage of Javascript is that it's immediately visible to the user but that probably isn't critical in this case.

Bob
LandShark 06 Mar, 2012
Thanks Bob,
So would I put that php code in the custom code action of the onSubmit event?
GreyHead 06 Mar, 2012
Hi LandShark ,

Yes that's it. drag the action after any Check Captcha and/or Validation actions and before your DB Save and Email actions.

Bob
LandShark 06 Mar, 2012
Bob,
Thanks for help with this. One more question:
I can get the value of a form field with this php code:

$a=$form->data['Name'];

Now is it possible to stuff that value into the value of another form field? And to do this before I hit the confirmation page? So instead of putting the value into a variable $a, I want to put it in a different form field like this:

$data['OtherName']=$form->data['Name']; (of course not just like that since that won't work)

In other words, set the form data instead of get it.
GreyHead 07 Mar, 2012
Hi Landshark,

If you have the republish setting set to Yes in the Show HTML action then ChronoForms will try to republish i.e. add values to any input with a name that matches a name in the $form->data array.

The $form->data array is automatically loaded with any parameter values from the page URL and any POST values (if you are arriving from another form).

All this is a long way of saying that this should work OK, it's slightly different from yours
$form->data['OtherName'] = $form->data['Name'];


Bob
LandShark 07 Mar, 2012
Thanks Bob,
That did the trick!
This topic is locked and no more replies can be posted.