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:


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!

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:

$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>

Hope you understand and can plug it in your code.

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!

Why not just use a URL paramater and a link (instead of a form) from the various pages.

<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

$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.

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.