If/Else PHP Question - How to Use w/ <select> tag

Garrett

music LOUD
Feb 4, 2008
3,847
131
0
I am trying to figure out how I can do a PHP if (option 1 isset) { go here }.

Basically, I have a squeeze page that is capturing whether male/female, age, weight, and height. To start... I figure I should probably send the males to different landers than females (and eventually send young vs. old males/females to different spots too).

Here's the form on my squeeze page:

Code:
<form action="results.php" method="get">
			<fieldset>
			<legend>Step #1:</legend>
			<table>
			<tr>
				<td><span>Sex</span></td>
				<td>
				<select name="sex">
					<option value="1">SELECT</option>
					<option value="2">Male</option>
					<option value="3">Female</option>
				</select>
				</td>
			</tr>
					
			<tr>
				<td><span>Weight (lbs)</span></td>
				<td><input type="text" name="weight" value="" style="background:#eee; padding:3px; border:1px solid silver; font-size: 17px; margin-top:8px;font-weight:bold;" /></td>
			</tr>
				
			<tr>
				<td><span>Height (inches)  <a class="popup" href="javascript:popup()">?</a> </span></td>
				<td><input type="text" name="height" value="" style="background:#eee; padding:3px; border:1px solid silver; font-size: 17px;font-weight:bold;" /></td>
			</tr>
					
			<tr>
				<td><span>Age (years)</span></td>
				<td><input type="text" name="age" value="" style="background:#eee; padding:3px; border:1px solid silver; font-size: 17px;font-weight:bold;"/></td>
			</tr>
					
			<tr>
				<td colspan="2" align="right"><input type="submit" value="What's my resting metabolic rate?" style="margin-top:4px;margin-bottom: 10px;position:relative;right:40px;" /></td>
			</tr>
			</table>
			</fieldset>
		</form>

My results.php file has a function that does a calculation and echoes it back to the user. How do I use PHP to tell which option has been selected?

Code:
if( isset($_GET['???'])

Also, I'm thinking Im gonna need to use an intermediary script (i.e. action url)to tell whether male/female (so I can forward them to different landers)... and at the same time, pass the variables they entered to the final lander.

If anyone can help me on this one, I'll hook you up for sure.
 


You need to add some code like
Code:
        <input type="submit" name="SubmitForm" value="Send">
This wil be the button the user presses to send data. To then assign that sent data to a variable use:

Code:
if(isset($_GET['SubmitForm']))
{
    $variable = $_GET['sex'];
}

Not sure if this works I didn't look at your source to closely, I'm in work.

Hit me up if you have any more questions I can send you an example script.
 
just had a little look. Add a name variable to this line
Code:
input type="submit" value="What's my resting metabolic rate?"

for my example it would be name="SubmitForm"
 
PS: I would recommend using post method instead of get, thats a tiny bit to be on your url on the next page. Course its negligible if the php is going to immediately redirect to a lander after processing the info.

You don't really have to bother with submit name since you're primarily targeting the sex field. For example.

Code:
$sex = isset($_GET['sex'])?$_GET['sex']:0;

switch($sex)
{
  case 0: /* not set, do something here */ break;
  case 1: /* not selected, do something here */ break;
  case 2: /* Male, do something here */ break;
  case 3: /* Female, do something here */ break;
}

and so on.
 
Ahhhh.... I feel stupid. Just store it as a variable (I'm a php newb lol). I think I might be able to hack it together now.