Using a link to populate a form field

Hi all,

I want to be able to auto populate a form field based on the contents of a link.

For example, if have a page that contains a product called “Product 001” I want to have a link underneath the product that will take the user to an enquiry form such as the one here: http://www.ask4tractors.com/index.php?option=com_rsform&view=rsform&Itemid=7 and auto populate the subject field with the words “Product 001”. i.e. I want the contents of the subject field to be populated according to the page from which it was linked.

I’m hoping I can do this by adding some code to the end of the standard link.

Can anyone help?

Thanks.

If you are using PHP then you can use the $_GET variable


nextpage.php?enquiry=Product001


$link = $_GET['enquiry'];

grab that value on the form page...

then use that value in your form


<input type="text" name="enquiry_subject" value="<?php echo $link; ?>" />

Thanks SpikeZ.

I’m pretty crap when it comes to anything other than HTML and CSS so might need a bit more help…

I’m guessing the first bit of code is the link, and the last bit of code goes in the HTML form.

But where does the PHP go? I’m using Joomla for my cms.

Thanks.

To make it easier and because I dont know Joomla’s way of working you can combine the php and form parts.

So on your form input use:


<div class="formField"><p>
		Subject *<br/>
		<input type="text" value="<?php if(isset($_GET['enquirySubject'])) { echo $_GET['enquirySubject']; } ?>" size="20"  name="form[Subject]" id="Subject" /><br/>
		<span id="component12" class="formNoError">Please write a subject for your message.</span>
		</p>
	</div>

This checks to see if the $_GET value has been sent in the URL, if it has then it will print it into the form input.

The complete link would need a little bit appending to it:


http://www.ask4tractors.com/index.php?option=com_rsform&view=rsform&Itemid=7&enquirySubject=subject of the enquiry