SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard bronze trophy conradical's Avatar
    Join Date
    Jan 2005
    Location
    Atlanta
    Posts
    2,355
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)

    Passing a choice from one page to another - and display as a selected <option>

    Hey guys - I have three pages:
    1. Hero.php
    2. Partner.php
    3. Client.php

    Basically, a user can choose to become a Hero, a Partner or a Client. On each of these pages there is an Apply button. This apply button from all three pages goes to the same application form.

    If the user clicks on the Apply button from the Hero page, then at the top of the Application form, "Hero" should display as the selected option: Ex, the HTML would look like this:
    Code HTML4Strict:
    <select>
    <option>Hero</option>
    <option>Partner</option>
    <option>Client</option>

    This way, the user can change their selection on the application form. Likewise, if they click on the Apply button from the Partner page then Partner should display as the selected option on the Application form.

    Thanks! Help is appreciated!

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Once an option is selected, submit the form and store the selected value in a SESSION, COOKIE and get that value to check if it has been selected already and make selected attribute true in the option in the drop down. I assume you store it in the cookie, the code will look like this:
    PHP Code:
    $selected_value = isset($_COOKIE['option_type']) ? $_COOKIE['option_type'] : '';
    echo 
    '<select name="option_type">
        <option' 
    . ($selected_value == 'Hero' ' selected=""' '') . '>Hero</option>
        <option' 
    . ($selected_value == 'Partner' ' selected=""' '') . '>Partner</option>
        <option' 
    . ($selected_value == 'Client' ' selected=""' '') . '>Client</option>
    </select>'

    Hope you understand and can plug it in your code.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    SitePoint Wizard bronze trophy conradical's Avatar
    Join Date
    Jan 2005
    Location
    Atlanta
    Posts
    2,355
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Thanks for that. I have a feeling that there is a part one to this? The part about saving it to a cookie? Do you have any clues how that is done? Or point me to a link/resource with a tip!

  4. #4
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not just use a URL paramater and a link (instead of a form) from the various pages.

    HTML Code:
    <a href="apply.php?t=Hero">Apply</a>   <!-- hero page -->
    <a href="apply.php?t=Partner">Apply</a>   <!-- partner page -->
    <a href="apply.php?t=Client">Apply</a>   <!-- client page -->
    Then on apply.php
    PHP Code:
    $types = array('Hero''Partner''Client');

    $select "<select>";

    foreach(
    $types as $t) {
       
       
    $s = ( isset($_GET['t']) AND $_GET['t'] == $t ) ? 'selected' '';
     
       
    $select .= "<option value='$t$s>$t</option>
    }
    echo 
    $select . "</select>"; 
    You can style the links to look like buttons.

  5. #5
    SitePoint Wizard bronze trophy conradical's Avatar
    Join Date
    Jan 2005
    Location
    Atlanta
    Posts
    2,355
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Thanks! That was exactly what I was looking for.. the PHP was pretty easy to follow as well - so I get the concepts and hopefully can expand on that. Thank you.


Bookmarks

Posting Permissions

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