Hello, I'm new to the forum and to php.
I have questions regarding submitting forms. My test form has 3 input fields: name, email and zipcode.
Is it best-practice to submit the form to the same page? Or to submit it to a different page and then redirect back to the first page to show an error or success message via session vars?
I'm assuming the perk to submitting to the same page is to avoid the need to use cookies/sessions to save field values to repopulate the fields text values when there is an error? Eg: they filled out name and email, but left zipcode blank -they shouldn't have to re-enter their name and email.
Question about submitting forms
Moderator: General Moderators
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Re: Question about submitting forms
Hi incubusor and welcome to the DevNetwork! 
I validate at both the client and the server, by doing so you minimize the chances that you'll need to validate at the server (reduces load for the majority of visitors) while you can not negate the need to validate form data at the server (to fend off possible attacks).
As far as a redirect page versus a direct post it all depends on your goal. The redirect page works nicely to prevent double posts from what I've witnessed. If you directly post depending on your situation you may have to mesh your functions for the rest of your site together whereas if you are taking the form data per particular page you can reduce overall complexity (though you generate more pages for the client).
So I think it barrels down to your individual goals. I'm more of an intermediate level PHP programmer right now at best so I'd recommend being open to some of the (coding) heavyweights around here.
I validate at both the client and the server, by doing so you minimize the chances that you'll need to validate at the server (reduces load for the majority of visitors) while you can not negate the need to validate form data at the server (to fend off possible attacks).
As far as a redirect page versus a direct post it all depends on your goal. The redirect page works nicely to prevent double posts from what I've witnessed. If you directly post depending on your situation you may have to mesh your functions for the rest of your site together whereas if you are taking the form data per particular page you can reduce overall complexity (though you generate more pages for the client).
So I think it barrels down to your individual goals. I'm more of an intermediate level PHP programmer right now at best so I'd recommend being open to some of the (coding) heavyweights around here.