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!

Server side validation

Status
Not open for further replies.

geminihk

Programmer
Nov 11, 2002
21
0
0
HK
Hi All,

I have a form in pag1.asp which excutes page2.asp when submit button clicked.

In page2.asp I'm doing server side validation and if any error I want to post the error to page1.asp and post back the already entered values.

I don't want to use session or cookies.

Is there any other alternative way to do this?

Thanks in advance.
 
on page2 gather the results into variables using the request object.

Do your validation on the values and dynmaically create another form (hide it with css) on page2.

If there are errors, use javacript to submit that form back to page1. if there are no errors proced as normal.

Or - collect all the results and make a string of errors and redirect the user back to page1 with the string of errors in the querystring.

--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
Thanks vicvirk.

Yes. I do know that. But would like to find any other option, because

1. i don't want to use javascript - what happens if the javascript is disabled?

2. query string - i don't want to show the details in the error message.

any idea?

Thanks.

 
Hi,

>> 1. i don't want to use javascript - what happens if the javascript is disabled?

People with javascript disabled are used to re-entering information on forms, but you should be using javascript validation too. (before it even submits)

>> 2. query string - i don't want to show the details in the error message.

Why ?

I think Vicvirk means redirecting to page1.asp?err=2 (for example).. with something like this in page1.asp..

Code:
<div id="inform">
<%
Dim ErrMsg
ErrMsg = Request.Querystring("err")

If Trim(ErrMsg) <> "" Then

Select Case ErrMsg
	Case "0"
Response.Write "&nbsp;Uknown Error Occured, Please Report Error Number : 8745.&nbsp;" 'catch Unknowns(should never happen)
	Case "1"
Response.Write "&nbsp;An Account With This user name and/or email address Already Exists."
	Case "2"
Response.Write "&nbsp;Password Does Not Match Password Confirm.&nbsp;"
	Case "3"
Response.Write "&nbsp;Email Address Is Invalid.&nbsp;"
	Case "4"
Response.Write "&nbsp;User Name Too Long (1 to 15 Letters and/or Numbers).&nbsp;"
	Case "5"
Response.Write "&nbsp;Enter A User Name And Email Address.&nbsp;"
	Case "6"
Response.Write "&nbsp;Invalid Characters Entered; A-Z/a-z Letters And Numbers Only.&nbsp;"
	Case "7"
Response.Write "&nbsp;Password Length Is Incorrect.&nbsp;"
	Case "8"
Response.Write "&nbsp;A Confirmation Email Has Been Sent.&nbsp;" 'succsess
	Case Else
Response.Write ""
End Select

End If
%>

Your main goal is to inform the user every step of the way to help them fill the form in correctly, I'd normally do this via JS and the very VERY few users with JS disabled with then see the contents of the inform DIV.



 
geminihk (Programmer) 22 Sep 09 21:09 said:
Thanks vicvirk.

Yes. I do know that. But would like to find any other option, because

1. i don't want to use javascript - what happens if the javascript is disabled?
Read what Mark said

geminihk (Programmer) 22 Sep 09 21:09 said:
2. query string - i don't want to show the details in the error message.
Read what Marks said (I actually suggested passing the actual values, but Mark had a good point as well).

The other option is to have the form on page1.asp to submit to page1.asp, do the validation and if all is good do what you need to do and redirect to page2.asp. If there are errors, write the valid ones to the db and don't redirect, rather fill the form in with the values that were entered.

What I don't understand in your scenerio is why you don't want to use session variables - this is exactly what session variables are there for - the javascript makes sense, but Mark summed that up - people are used to having a "not-so-easy" time when they turn off js.

It would be best to get one set of data (fully validated) otherwise a user could be making multiple requests to the db.





--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
forget about what I said about writing valid entries to the db...

you can do it this way (it's not tested, but if there are any errors, you should be able to spot them when you test it) - I just quickly wrote it out

Code:
<%
	blnFormSubmitted = false 'by default the form was not submitted
	
	' if the submit button was clicked
	if request.form("btnSubmit") = "Submit" then
		' get/validate the data submitted
		blnFormSubmitted = true
		blnErrorFound = false 'by default it's all good
		errMsg = "" 'no error message to start
		user_first_name = request.form("tbxFirstName")
		user_last_name = request.form("tbxLastName")
		if user_first_name = "" then errMsg = errMsg & "First name is required<br />"
		if user_last_name = "" then errMsg = errMsg & "Last name is required<br />"
		if errMsg <> "" then blnErrorFound = true
	end if
	
	if blnFormSubmitted and not blnErrorFound then
		' process the data
		' redirect user to next page (i.e. page2.asp)
	elseif blnFormSubmitted and blnErrorFound then
		response.write "There were errors in your form:<br />" & errMsg
	end if
%>
<form action="page1.asp" method="post">
	First Name: <input type="text" id="tbxFirstName" name="tbxFirstName" value="<%=user_first_name%>" /><br />
	Last Name: <input type="text" id="tbxLastName" name="tbxLastName" value="<%=user_last_name%>" /><br />
	<input type="submit" id="btnSubmit" name="btnSubmit" value="Submit" />
</form>


Code:
' whatever this page needs to be


--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
Thanks Vicvirk & Mark for your effort.

I do have a client side validation.

I did liked Mark idea, but in this way we can not retain the correct FORM Values.

After all these finally I opted to use Session variables.

Thanks once again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top