Page 289 - Beginning PHP 5.3
P. 289
Chapter 9: Handling HTML Forms with PHP
function setChecked( $fieldName, $fieldValue ) {
if ( isset( $_POST[$fieldName] ) and $_POST[$fieldName] == $fieldValue ) {
echo ‘ checked=”checked”’;
}
}
function setSelected( $fieldName, $fieldValue ) {
if ( isset( $_POST[$fieldName] ) and $_POST[$fieldName] == $fieldValue ) {
echo ‘ selected=”selected”’;
}
}
function processStep1() {
displayStep2();
}
function processStep2() {
if ( isset( $_POST[“submitButton”] ) and $_POST[“submitButton”] ==
“< Back” ) {
displayStep1();
} else {
displayStep3();
}
}
function processStep3() {
if ( isset( $_POST[“submitButton”] ) and $_POST[“submitButton”] ==
“< Back” ) {
displayStep2();
} else {
displayThanks();
}
}
function displayStep1() {
?>
<h1>Member Signup: Step 1</h1>
<form action=”registration_multistep.php” method=”post”>
<div style=”width: 30em;”>
<input type=”hidden” name=”step” value=”1” />
<input type=”hidden” name=”gender” value=”<?php setValue
( “gender” ) ?>” />
<input type=”hidden” name=”favoriteWidget” value=”<?php setValue
( “favoriteWidget” ) ?>” />
<input type=”hidden” name=”newsletter” value=”<?php setValue
( “newsletter” ) ?>” />
<input type=”hidden” name=”comments” value=”<?php setValue
( “comments” ) ?>” />
<label for=”firstName”>First name</label>
<input type=”text” name=”firstName” id=”firstName” value=”<?php
setValue( “firstName” ) ?>” />
<label for=”lastName”>Last name</label>
251
9/21/09 7:23:44 PM
c09.indd 251
c09.indd 251 9/21/09 7:23:44 PM