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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

340<br />

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

// Stores the value of the submit button<br />

submitVal = $(this).val(),<br />

// Determines if the event should be removed<br />

remove = false,<br />

// Saves the start date input string<br />

start = $(this).siblings("[name=event_start]").val(),<br />

// Saves the end date input string<br />

end = $(this).siblings("[name=event_end]").val();<br />

// If this is the deletion form, appends an action<br />

if ( $(this).attr("name")=="confirm_delete" )<br />

{<br />

// Adds necessary info to the query string<br />

formData += "&action=confirm_delete"<br />

+ "&confirm_delete="+submitVal;<br />

}<br />

// If the event is really being deleted, sets<br />

// a flag to remove it from the markup<br />

if ( submitVal=="Yes, Delete It" )<br />

{<br />

remove = true;<br />

}<br />

// If creating/editing an event, checks for valid dates<br />

if ( $(this).siblings("[name=action]").val()=="event_edit" )<br />

{<br />

if ( !validDate(start) || !validDate(end) )<br />

{<br />

alert("Valid dates only! (YYYY-MM-DD HH:MM:SS)");<br />

return false;<br />

}<br />

}<br />

// Sends the data to the processing file<br />

$.ajax({<br />

type: "POST",<br />

url: processFile,<br />

data: formData,<br />

success: function(data) {<br />

// If this is a deleted event, removes<br />

// it from the markup<br />

if ( remove===true )<br />

{<br />

fx.removeevent();<br />

}

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

Saved successfully!

Ooh no, something went wrong!