PDA

View Full Version : Pre-select form elements based on history



jjspelman
03 Apr 2011, 09:22 AM
Hi,

My client would like me to build a simple PHP form for viewers to select items they would like more information on. No problem. They would like the form to be pre-selected with an item they just selected on a previous page.

In other words, if they were looking at a vacation page describing a trip to vegas, and they click "buy now", (btw, there will be no shopping cart) or "more info", the subsequent form on the resulting page would have that vacation preselected.

This is requested in an effort to keep the clicks to a minimum for the user.

Couldn't this be done by attaching an "ID" to the "more info" button on what ever page they came from?

Your help is appreciated.

djlebarron
03 Apr 2011, 10:05 AM
This would be your "More Info" button:
<a href="form.php?id=Vegas"><img src="more_info.gif" /></a>
On "form.php" you would put:
<?php $vacation = $_GET['id']; ?>
Then use something like <?php echo "yourhtml".$vacation."morehtml"; ?>, to echo the whole form and put the variable $vacation value where you want it to be. Or, simply use <?php echo $vacation; ?> inline in your form to place the variable value in the proper place.

That's a simple example. If (like above) I was using an "a" link button, I'd probably use sprites and use a span for my text link to get more SEO out of it. An alternative would be to use a "hidden" form like this:

<form name="info" action="form.php" method="post">
<input type="hidden" name="more_info" value="Vegas">
<input type="submit" value="More Info">
</form>

Then on "form.php":
<?php $vacation = $_POST['more_info']; ?>
And so on. The second method would enable you to pass the variable onto "form.php" without showing it in the url of "form.php". Again, a simple example. Don't forget to include the proper security measures.