Msg#: 4453677 posted 3:37 pm on May 15, 2012 (gmt 0)
here's how I'd do it. you can clean up the <table> HTML later
first, your form needs to be in a <form> so it submits to somewhere, with method=post
then, only do the comparison if the form is a postback, ie it's not going to happen unless someone pressed submit. There are many ways to do that but I like to put a hidden input in the form that you can check if it exists
Msg#: 4453677 posted 3:48 pm on May 15, 2012 (gmt 0)
you can further enhance the form in a many ways...
2) populate the fields with the _POST values, so if they mess up they can correct what they did, and don't have to re-type everything again. This is especially important since it's a contact form, and they might have spent 20 minutes writing something which would be lost if they did a dumb typo in the email address
3) trim and lowercase the comparison, so "email@example.com " will match "Me@Example.Com " - it's more forgiving in case they do something weird in the form
4) output something more sensible than "true" and "false"
5) do your validation at the top of the script, not inline... do something different if validation passes, eg write the stuff into a database or send an email, and show a confirmation message instead of showing the same form again
6) ... etc
I get that this is a work in progress, and you'll enhance it l8r to make it user friendly & functional
Forms are complex things, but once you've done it a dozen times you'll get the knack.