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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best way to check data before it's saved to database? 1

Status
Not open for further replies.

snowxf

Technical User
Jan 5, 2005
20
US
Please bounce some ideas my way about how to check data from a form's elements before they're saved to a database!

To be more specific:
I have an "edit" page that displays a record, with each field in a textbox. However some fields, like the dates, have size limits or are specific types (Date/Time) in the database, and therefore those fields need to be checked before they're sent to the database and an error is generated. Right now the form action posts to a second "updated" page that calls an "updateRecord" sub and simply displays a message that the record has been updated. Ideally, if something needs changed on the form, it won't go to the second page at all, but might display some text at the top/bottom of the form or in a pop-up stating what's wrong. Then when the page is submitted, and everything checks out okay, it will open a recordset and update the record.

Any suggestions?? My brain's out of steam on this one...
 
You can rely on client-side validation as long as you trust your users not to fiddle with your form or disable client-side scripting.

If the users have anything to gain by monkeying with the system then you should do the field validations in server side script, immediately before you call your "updateRecord" sub.
 
My users might fiddle with the form, but without knowing it. So, I guess server-side it is (plus my javascript's pretty limited). I guess if it doesn't validate, have a message stating what didn't validate, with a link that simply goes back to the page (without reloading)? Since this is what I'm thinking now, would you happen to know how to create a link that just goes back one page in the browser's history?
 
Well you could make a button with a javascript function like this:
Code:
<INPUT type="button" value="<- Back" onClick="history.back()">

Or if you want to go back multiple pages like this:
Code:
<INPUT type="button" value="<- Back 2" onClick="history.go(-2)">

Or, if you are submitting a fairly short form, you can just use Response.Redirect back to the page, and put the user's orignal values into the QueryString or a Cookie... also you could put the explanation here as well... then just change the form page to read these values if they exists and pre-populate the field with them.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top