puts the date and time functions to work in displaying a calendar. The
show_form( ) function in Example 9-17 displays a form that asks for a
month and year. The
process_form( ) function hands those values off to
show_calendar( ) function, which does the real work
of printing a calendar grid for a particular month.
The structure of the
if( ) statement that controls
validate_form( ), and
process_form( ) is different in Example 9-17 than in previous form examples. That's because we want to
display the form above the calendar. Usually, if the form data is valid,
show_form( ) is not called—only
process_form( ) is. But here,
) is called before
process_form( ) so that
the form is displayed above the calendar and the user can pick another month and year to
Similarly, the call to
show_form( ) that happens
when the form has not been submitted (when there is no
$_POST['_submit_check'] parameter) is followed by a call to
show_calendar( ) to display the calendar for the current
month the first time the page is loaded.
Example 9-17. Printing a calendar
<?php // Use the form helper functions defined in Chapter 6 require 'formhelpers.php'; $months = array(1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April', 5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August', 9 => 'September', 10 => 'October', 11 => 'November', 12 => 'December'); $years = array( ); for ($year = date('Y') - 1, $max_year = date('Y') + 5; $year < $max_year; ...