Page 283 - Beginning PHP 5.3
P. 283
Chapter 9: Handling HTML Forms with PHP
<option value=”megaWidget”<?php setSelected( “favoriteWidget”,
“megaWidget” ) ?>>The MegaWidget</option>
<option value=”wonderWidget”<?php setSelected( “favoriteWidget”,
“wonderWidget” ) ?>>The WonderWidget</option>
</select>
<label for=”newsletter”>Do you want to receive our newsletter?
</label>
<input type=”checkbox” name=”newsletter” id=”newsletter” value=”yes”
<?php setChecked( “newsletter”, “yes” ) ?> />
<label for=”comments”>Any comments?</label>
<textarea name=”comments” id=”comments” rows=”4” cols=”50”><?php
setValue( “comments” ) ?></textarea>
<div style=”clear: both;”>
<input type=”submit” name=”submitButton” id=”submitButton” value=
”Send Details” />
<input type=”reset” name=”resetButton” id=”resetButton”
value=”Reset Form” style=”margin-right: 20px;” />
</div>
</div>
</form>
<?php
}
function displayThanks() {
?>
<h1>Thank You</h1>
<p>Thank you, your application has been received.</p>
<?php
}
?>
</body>
</html>
Now browse the script’s URL in your Web browser. You’ll see a blank registration form. Try
submitting an empty form by clicking Send Details. You should see an error message, with the missing
required fields highlighted. If you fill in some values and resubmit, the script keeps checking to see if
you’ve filled in the required fields. If not, it redisplays the form, including any data you’ve already
entered, and highlights the missing fields, as shown in Figure 9-7.
245
9/21/09 7:23:42 PM
c09.indd 245
c09.indd 245 9/21/09 7:23:42 PM