Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Validation problem

Status
Not open for further replies.

glenc175

Technical User
Sep 27, 2002
13
GB
I have written a php page that presents a form for adding a new member to a dbase. This worked ok. I then wanted to add form validation to make sure certain field were filled in. (using DW form validate behaviour with 'onsubmit') this works as far as it pops up a list of errors for any unfilled required fields, but when 'OK' is clicked, acknowledging the error(s), the script seems to continue, without letting the user correct the omissions, and goes to the page in the forms 'action' parameter i.e it apparently submits the form but does not affect the dbase.
How do I stop the php script continuing, allowing the errors to be corrected?
 
this is a js problem... it happens always in IE if the event is given onsubmit even if an error is found the page WILL SUBMIT... to overcome this it is better to debug the page that shows the error by changing the submit button to an ordinary button and calling the function in the onclick event...

Known is handfull, Unknown is worldfull
 
gelnc,

An alternative is to have the PHP script validate the form data. There are still people out there that switch JavaScript off - and so your validation would go out the window and expected values will be missing in your PHP, the query will fail etc.

When you dynamically generate the form you can have it submit to itself, check out the required fields. If fields are missing, recreate the form (preserve the filled in values), give an error message in the appropriate spot.

That is really user freindly and you'll succeed in validation not depending on JavaScript.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top