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.

C H A P T E R 5<br />

■ ■ ■<br />

Add Controls to Create, Edit,<br />

<strong>and</strong> Delete Events<br />

Now that the calendar can be viewed, you need to add controls that will allow administrators to create,<br />

edit, <strong>and</strong> delete events.<br />

Generating a Form to Create or Edit Events<br />

To edit an event or add new events to the calendar, you need to use a form. You do this <strong>by</strong> adding a<br />

method called displayForm() that generates a form for editing <strong>and</strong> creating events to the Calendar class.<br />

This simple method accomplishes the following tasks:<br />

1. Checks for an integer passed as the event ID.<br />

2. Instantiates empty variables for the different fields used to describe events.<br />

3. Loads event data if an event ID was passed.<br />

4. Stores event data in the variables instantiated earlier if it exists.<br />

5. Outputs a form.<br />

■ Note By explicitly sanitizing the event ID passed in the $_POST superglobal, you ensure that the ID is safe to use<br />

since any non-integer values will be converted to 0.<br />

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

Saved successfully!

Ooh no, something went wrong!