Results 1 to 2 of 2

Thread: Pre-select form elements based on history

  1. #1
    Join Date
    Oct 2010
    Posts
    10

    Pre-select form elements based on history

    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.

  2. #2
    Join Date
    Sep 2008
    Posts
    899
    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.
    Last edited by djlebarron; 03 Apr 2011 at 01:03 PM.

Similar Threads

  1. Javascript: Make elements appear based on user interaction
    By mrtylersmith in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 18 Jul 2009, 04:40 PM
  2. Web Form that will Print only select info
    By rshaker90 in forum Web Design, HTML Reference and CSS
    Replies: 1
    Last Post: 16 May 2008, 08:24 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •