My form includes a link to populate some of the form with some contact details from the database. However when I click this link I lose all the values of the other form fields.
Here is the code where I call the page to retrieve the contact details from the database
<li>
<label class="label_block" for="businessName" >Accommodation Name:*</label>
<input type="text" id="businessName" name="businessName" type="text" VALUE="<?php echo stripslashes($businessName); ?>" />
</li>
<li>
<p><a href="createAccommodationListing.php?cmd=populateAddress&id=<?php echo $id; ?>&businessName=<?php echo $businessName; ?>">Click here to use same address as your registration address</a></p>
</li>
I also tried
<p><a href="createAccommodationListing.php?cmd=populateAddress&id=<?php echo $id; ?>&businessName=<?php echo document.myForm.businessName; ?>">Click here to
use same address as your registration address</a></p>
So essentially clicking the link calls the same php page. I just need to somehow pass the current field value of businessName
Thanks in advance
Paul
If you have register globals disabled (which you should), you must use $_GET[‘businessName’].
Tried that but it doesn’t appear to have any value
if($cmd=="populateAddress") {
$businessName = $_GET['businessName'];
echo "businessName = " . $businessName;
Neither $GET[id] or $id don’t exist anyway until you submit the form and by that register the variables.
Instead you can create a new FORM which uses the GET action and instead of a submit input button put an empty href link with an onClick function that submits your form.
Read about how to send forms using Javascript. (google)
<?php echo document.myForm.businessName; ?>
You’re mixed up with PHP and JS here.
Why not just make another submit button (with a name to you can disinguish which was clicked), so the details are sent with the click?
Another solution maybe to fire a onkeyup() function which saves the current value to a session via PHP (AJAX). That way when the user returns to the form their previous details where there.
Yeah but why not simply submit the form using the anchor tag? Save AJAX mess for when you really need it. 
Yeah, and users may get suspicious that you’re sending every keystoke to a php file.
Still, it’s an option.
Submitting the form through an anchor tag requires JavaScript, just like the AJAX option. Although it is handy to use, not every user has it enabled and you can’t let your applications suffer because javascript is disabled.
As a general rule, JavaScript should only be used to increase the user experience, not to play a key part in your applications.
Therefore your best solution is probably the extra submit button. It allows PHP to maintain your variables in, for example, a session, until they return to the page.
Ah I get you! Yeah I had a feeling I was mixing things up here. I guess I will go with the extra submit button though the idea was to save the user time by not having to enter their contact details again. Guess this will still be quicker.
Thanks everyone for the help!
Well, you can still implement that with the extra submit button.
Simply check for that button being pressed, and display the same form again with the original values and their address.
Oh cool - that sounds perfect then!
Thanks arkinstall!!!