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!

Validate on Submit

Status
Not open for further replies.

ronnetp

Programmer
Apr 8, 2002
71
I am new with ASP
I have a Form with 3 fields, one I need to validate
on submit, a customer number.

I need to validate if the customer exist on
the database before submiting.

I need to send an error if the customer does not
exists.

Thanks,

 
use a recordset object and request a recordset with the user info, if the recordset is EOF then add it, if it's not EOF then insert it.
 
a brief sample... hope this give you an idea..


set rs = Server.CreateObject("ADODB.Recordset")
with rs
.ActiveConnection = {YourConnectionString}
.Source = "SELECT * FROM CustTable where CustNo='" & request("CustomerNo")& "'"
.CursorType = 0
.CursorLocation = 2
.LockType = 3
.Open

if .eof then
ErrMsg = "Your Error Message"
end if

.close
end with

set rs = nothing

if ErrMsg <> &quot;&quot; then
response.write ErrMsg
response.end
end if
 
Thanks, for your help, I now how to do the connection and the query to the database, I dont know is how to
when the submit button is pressed, send an error
and dont continue with the action.

Thanks,
I hope you guys can help me, with this
 
I see two options.

1: Create a select box instead of an input one. This forces user to choose a valid customer.

2: Validate on the next page. If validation fails, send the user back to the form they just filled out using javascript.

You can't do more server side code on a page once it has been loaded and sent to the client.
 
Nevermoor's advice is sound. Why go through the checking process if you can populate the dropdown with the customers? Either way, validating on a separate page works great for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top