Chapter 7
Chapter 7
$_REQUEST[‘email’]; or $_GET[‘email’];
<input type="radio" name="gender" value="male">
$_REQUEST[‘gender’]; or $_GET[‘gender’];
…cont’d…
For Select element
<select name="age">
<option value="0-29">Under 30</option>
<option value="30-60">Between 30 and60</option>
<option value="60+">Above 60</option>
</select>
$_REQUEST[‘age’] or $_GET[‘age’];
…cont’d…
For Textarea
<textarea name="comment" cols="30“ rows="5">
</textarea>
$_REQUEST[‘comment’]; or $_GET[‘comment’];
Note: PHP is strictly case-sensitive when it
comes to value of ‘name’ attribute.
$_REQUEST[‘Comment’]; …doesn’t work
$_REQUEST[‘comment’]; …Correctly works
$_Request[‘comment’]; …doesn’t work
…cont’d…
As an option you can create the following kind of
table
HTML Form elements name PHP Syntax to get the input info
value
name $_REQUEST[‘name’]
email $_REQUEST[‘email’]
gender $_REQUEST[‘gender’]
age $_REQUEST[‘age’]
comment $_REQUEST[‘comment’]
btnS $_REQUEST[‘btnS’]
Use Conditionals and Operators
PHP’s three primary terms for creating conditionals are
if, else, and elseif(which can also be written as two
words, else if).
Every conditional begins with an if clause:
echo $lang.”<br>”;
}
foreach($langs as $key=>$lang){ //if keys are needed
echo “Element at Index $key is $lang <br>”;
}
…cont’d…
Can be used to create the following kinds of form
elements
…cont’d…
Create the months array
$months = array (1 => 'January', 'February', 'March', 'April', 'May',
'June', 'July', 'August', 'September', 'October','November',
'December');
Create the arrays for the days of the month and the years
$days = range (1, 31);
$years = range (2000, 2011);
Generate the month pull-down menu:
echo '<select name="month">';
foreach ($months as $key => $value) {
echo "<option value=\"$key\”>$value</option>\n";
}
echo '</select>‘;
…cont’d…
Generate the day and year pull-down menus:
echo '<select name="day">';
foreach ($days as $value) {
echo "<option value=\"$value\">$value</option>\n";
}
echo '</select>';