Origianlly posted by krelian]
Why not just use javascript to validate the input fields? Php is a waste IMO.
...And then some bright spark has Javascript turned off on their browser, or forges a form submission, or...
Have prophylactic Javascript running on the client by all means (90% of the time it will speed things up for the user and reduce server load), but basic safety precautions mean having equivalent (or stronger) checks running on the server at least - do you trust everyone else to do your safety checks for you, or do you do them yourself?
Very clever, I must say.
As for why the form is being redisplayed instead of the success page - well, that's exactly what you're asking for: redisplay the form (with the success page as the action).
If you want to redirect the user to the success page in the event of a successful submission, you can go
if([i]successful submission[/i])
{ header('Location: success.php');
exit;
}
...[i]continue and display form,
with any error messages as appropriate[/i]
One thing this would require is that all the form processing (and possible redirection) will have to be done before any HTML is generated. In other words, this code would have to be right at the very top of the page - otherwise your script will start haemorrhaging errors about "headers already sent". Reasonable enough if you think about it - if you want to give them another page (success.php) why would you be sending them this one?