all.
I've been thinking about a design decision for a PHP form and I'd like some input from people smarter than I am.
Here are the basics: I have a user input form which lets people register a chapter for a school. I'm doing input validation on the form fields, which lets me a) sanitize the data and b) validate the input. I then intend to send an email to the user who registered (as their email address will be submitted in the form) and write their information into a MySQL database.
Right now, I've got the data validation portion (and the requisite error messages) set up through POST, and the page is posting back to itself for the validation. This seemed logical to me as I could easily retain sanitized user input and display errors (for required fields, datatypes, whatnot). If all required fields are filled and the data is valid, I would like to redirect the user to a thank you page with extra information.
(Sorry I'm so verbose. I need to work on that.)
Thing is, I would like to separate the validation logic and the database write/email logic completely, if possible. My initial idea was to redirect to a thank you page if all fields were valid, but now I'm thinking that the thank you page should actually contain the logic to write to the DB, send an email, and then print the thank you message. This would, however, complicate things and involve passing POST data to another page without using GET. Although I've never had to do anything like this before (I'm fairly new to PHP), this is apparently possible (see here, here, and here) and there are multiple ways to accomplish this.
The question, though - should I even be trying to separate this logic in separate PHP pages? Every programming instinct tells me "hell yes, do it, it's a logical separation of responsibility"....but is this best practice for form handling in PHP? Can anyone with more PHP experience elaborate on the pros and cons of doing something like this, and their experiences? How would you do it?