The question says it all!
I have a form that needs to be validated with php (for javascript disabled browsers). Then, once all errors (if any) are handled, the data needs to be send to another php for processing. I found this post Same page processing useful because it took care of validation on the same page as the form - this saves me the need to pass back values to the original form...etc. [Right now I am ignoring the issue of back button and page refresh retaining the values - totally undesirable from my POV)
However, I noticed, in the same post, that it looks like all the form processing should also be placed on the same page as the form. This (I feel) will make the file ugly and a headache to maintain. So I was wondering:
What if I have the completed (error checked) form processing in a different php file? Is it possible to call that file (not by an include) or send the appropriate data (from the validation code or some other way) to the external processing file (similar to how we send POST data from the actual form)?
The reason I ask is, I have a working system where a form submits data to an external php file, that processes it and saves it to the database. Bad practice, I know, but I only thought of adding the validation after all this was done and working.
I guess it would be simple enough to copy all the code in the external php into the php that validates the form input, but somehow, it doesn't seem to be such a good idea! I would prefer to keep the 'saving to database' part of the processing in a separate file.
Hence the question:
- User fills in the form (form.php);
- PHP on the same page checks for errors and reloads the form with the entered data in case of errors (form.php).
- In case it does not encounter any errors, it sends (?) the data as (maybe) POST values to the processing file (process.php)
Is this possible? If it is please just give a hint - no code as I would like to learn how to do this myself!