phViewLoader::setInstance(new phFileViewLoader(dirname(__FILE__))); /* * also need to include our custom class phDateTime */ require_once 'phDateTime.php'; $form = new phForm('event', 'eventView'); /* * last 2 params say the only available year should * be 2011 */ $timeForm = new phDateTime('time', 'dateTimeView', 2011, 2011); /* * Add the datetime form as a subform to the master event * form. */ $form->addForm($timeForm); /* * add validators to the time so the date time chosen must be between * the start and end of January */ $errorMessage = array(phCompareValidator::INVALID => 'The event must occur sometime in January'); /* * setup a validator that says the datetime value given must be greater * or equal to the start of January 2011 */ $start = new phCompareValidator(strtotime('2011-01-01 00:00:00'), phCompareValidator::GREATER_EQUAL, $errorMessage); /* * setup a validator that says the datetime value given must be less * or equal to the end of January 2011 */ $end = new phCompareValidator(strtotime('2011-01-31 23:59:59'), phCompareValidator::LESS_EQUAL, $errorMessage);
phLoader::registerAutoloader(); phViewLoader::setInstance(new phFileViewLoader(dirname(__FILE__))); /* * create the main form */ $form = new phForm('deliver', 'deliveryForm'); /* * create the address form, the first argument * needs to match what we have in the form helper * on the deliveryForm template */ $address = new phForm('address', 'addressForm'); /* * add the sub form to the main form */ $form->addForm($address); if ($_SERVER['REQUEST_METHOD'] == 'POST') { /* * data has been posted back, bind it to the form */ $form->bindAndValidate($_POST['deliver']); if ($form->isValid()) { ?> <h1>Thanks!</h1> <p>We will deliver to <?php echo $form->address->address . ', ' . $form->address->city . ', ' . $form->address->zip; ?> </p> <?php }