02.06.2013 Views

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

334<br />

CHAPTER 9 ■ PERFORMING FORM VALIDATION WITH REGULAR EXPRESSIONS<br />

}<br />

?><br />

}<br />

*/<br />

$pattern = '/^(\d{4}(-\d{2}){2} (\d{2})(:\d{2}){2})$/';<br />

/*<br />

* If a match is found, return TRUE. FALSE otherwise.<br />

*/<br />

return preg_match($pattern, $date)==1 ? TRUE : FALSE;<br />

private function _loadEventData($id=NULL) {...}<br />

private function _createEventObj() {...}<br />

private function _loadEventById($id) {...}<br />

private function _adminGeneralOptions() {...}<br />

private function _adminEntryOptions($id) {...}<br />

Returning an Error if the Dates Don’t Validate<br />

Your next step is to modify the processForm() method so it calls the _validDate() method on both the<br />

start <strong>and</strong> end times for new entries. If the validation fails, simply return an error message.<br />

Add the following bold code to processForm() to implement the validation:<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!