ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 1st, 2005, 05:04 PM
Discusman Discusman is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 346 Discusman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 2 h 38 m 12 sec
Reputation Power: 0
User Input Validation Problem

I am trying to do something that prevent user submit blank data to my database.

Here is my code:

strSubject = upload.Form("subject")
strContent = upload.Form("comment")

If (strSubject="") Then
Response.Redirect "http.....asp"
Else
If (strContent="") Then
Response.Redirect "http:...asp"
End If
End If

When only the content is blank and subject line has text.
This validation doesn't work. It allow ppl enter empty data to content.

If the subject leaves blank, then this validation works.

What is wrong?

Reply With Quote
  #2  
Old February 1st, 2005, 05:21 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
Try something like this
Code:
If Len(strSubject) = 0 Then
   Response.Redirect("http://...asp")
End If

If Len(strContent) = 0 Then
   Response.Redirect("http://...asp")
End If 

Reply With Quote
  #3  
Old February 1st, 2005, 08:22 PM
Discusman Discusman is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 346 Discusman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 2 h 38 m 12 sec
Reputation Power: 0
Quote:
Originally Posted by Memnoch
Try something like this
Code:
If Len(strSubject) = 0 Then
   Response.Redirect("http://...asp")
End If

If Len(strContent) = 0 Then
   Response.Redirect("http://...asp")
End If 


It's samething. Not working.

I was wondering if I can create a function to check the user input. If it is blank, then prompt user an error message at client?

I'm using this as my prefilled text field. It will be stored in the database again. I do not want ppl delete everything and submit a empty data to the table.
<INPUT STYLE="width: 715px" TYPE="Text" NAME="subject" VALUE="<%Response.Write objRS("Subject")%>" SIZE="20" MAXLENGTH="75">

How can I modify this to validate the text field before submission? Thanks.

Reply With Quote
  #4  
Old February 1st, 2005, 09:30 PM
vicvelvett vicvelvett is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 16 vicvelvett User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 41 m 46 sec
Reputation Power: 0
I would definitely recommend doing your validation on the client. Attach it to your submit button with something like:

<input type=button onClick="ValidateInput()" value="Submit">
<script>
If(form1.subject=="")
{
alert("Please enter subject.");
}
else
{
form1.submit
}
</script>

Reply With Quote
  #5  
Old February 1st, 2005, 10:06 PM
Discusman Discusman is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 346 Discusman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 2 h 38 m 12 sec
Reputation Power: 0
Quote:
Originally Posted by vicvelvett
I would definitely recommend doing your validation on the client. Attach it to your submit button with something like:

<input type=button onClick="ValidateInput()" value="Submit">
<script>
If(form1.subject=="")
{
alert("Please enter subject.");
}
else
{
form1.submit
}
</script>


How about validating both subject and comment field?
How should I modify this function to make it work? Thanks.

Reply With Quote
  #6  
Old February 1st, 2005, 10:08 PM
Discusman Discusman is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 346 Discusman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 2 h 38 m 12 sec
Reputation Power: 0
Quote:
Originally Posted by vicvelvett
I would definitely recommend doing your validation on the client. Attach it to your submit button with something like:

<input type=button onClick="ValidateInput()" value="Submit">
<script>
If(form1.subject=="")
{
alert("Please enter subject.");
}
else
{
form1.submit
}
</script>


My button is:
<INPUT TYPE="SUBMIT" NAME="send" VALUE="UPDATE" Class="button">

How can I modify it to work with your function?

Reply With Quote
  #7  
Old February 1st, 2005, 10:22 PM
lewy's Avatar
lewy lewy is offline
Alter Ego Wizard
ASP Free Specialist (4000 - 4499 posts)
 
Join Date: Jun 2004
Location: Edinburg Tx
Posts: 4,381 lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 1009 Folding Title: Novice Folder
Time spent in forums: 1 Month 1 Week 1 Day 23 h 7 m 43 sec
Reputation Power: 1488
Here is a way in which you can use some of the ideas shared above.
Code:
<html>
 <head>
 <script language="JavaScript">
 function validate()
 {
   if (document.main.subject.value=="")
   { 
 	 
 	 alert("Subject Must contain a value");
 	 return false;
   }
   else
 	{ 
 	  if (document.main.comment.value == "")
 	  { 
 		 alert("Comment Must contain a Value");
 	 return false;
 	  }
 	  else
 	   { return true; }
 	}
 }
 </script>
 </head>
 
 <body>
 <form name="main" action="" onSubmit="return validate();">
 <input type="text" name="subject" size="20">
 <br>
 <input type="text" name="comment" size="20">
 <br>
 <input type="submit" value="Update">
 </form>
 </body>
 </html>

Test it, it should give you what you want, make sure that you put an action on the <form> tag.
Post back if you have any questions

Reply With Quote
  #8  
Old February 1st, 2005, 10:30 PM
vicvelvett vicvelvett is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 16 vicvelvett User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 41 m 46 sec
Reputation Power: 0
Quote:
Originally Posted by Discusman
How about validating both subject and comment field?
How should I modify this function to make it work? Thanks.


Sorry, I sent you some incomplete code last time. To validate other fields you just put an else if statement:
Code:
<SCRIPT LANGUAGE=javascript>
<!--
function ValidateInput()
{
if(form1.subject.value=="")
{
alert("Please enter subject.");
}
else if(form1.comment.value=="")
{
alert("Please enter comment.");
}
else
{
form1.submit
}
}
//-->
</SCRIPT>
 


You should change your button type from "SUBMIT" to "BUTTON" because you want the code to validate before you submit.

Yes! The one above is much cleaner. Go with that.

Reply With Quote
  #9  
Old February 2nd, 2005, 10:38 AM
Discusman Discusman is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 346 Discusman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 2 h 38 m 12 sec
Reputation Power: 0
Form Action Question

In the action property, I have the URL of ASP code page that will process this form submission.

So since I need to put onsubmit validate(), where do I put that URL?

My form looks like this:

<FORM NAME="frmSend" ACTION="http://.......asp" METHOD="POST">

Reply With Quote
  #10  
Old February 2nd, 2005, 10:39 AM
Discusman Discusman is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 346 Discusman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 2 h 38 m 12 sec
Reputation Power: 0
Ok,, I see what I have did wrong. Never mind.


Thanks.

Reply With Quote
  #11  
Old February 2nd, 2005, 10:54 AM
Discusman Discusman is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 346 Discusman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 2 h 38 m 12 sec
Reputation Power: 0
It's not working....

I do not know why this is not work. I have tried all kinds of user input validation methods. None of them works.

Here is the story. Currently I am working on user input validation on Modify function.

When user clicks on Modify button, it will allow them modify their posts. In order to prevent them submitting empty data to the database. I need to add some type of user input validation.
Here is the code:
=======================
<script language="JavaScript">
function validate()
{
if (document.ModifyMessageSend.subject.value=="")
{

alert("Subject Must contain a value");
return false;
}
else
{
if (document.ModifyMessageSend.comment.value == "")
{
alert("Comment Must contain a Value");
return false;
}
else
{ return true; }
}
}
</script>
=============================
The code of the form:
=============================
<FORM NAME="ModifyMessageSend" ACTION="http://...ProcessSubmission.asp"
onSubmit="return validate();" METHOD="POST">
<TABLE BORDER=0>
<TR>
<TD><INPUT STYLE="width: 715px" TYPE="Text" NAME="subject" VALUE="<%Response.Write strSubject%>" SIZE="20" MAXLENGTH="75"></TD>
</TR>

<TR>
<TD><TEXTAREA NAME = "comment" ROWS = "13" COLS = "87">
<%Response.Write strContent%></TEXTAREA>
</TD>
</TR>

<%If objRS("filestat")="1" Then%>
<tr valign=center>
<td><span class="mytext">Remove attached photo?
<INPUT TYPE="radio" NAME="FileStat" Value="yes">Yes
<INPUT TYPE="radio" NAME="FileStat" Value="no">No
</span></td>
</tr>
<%Else%>
<tr>
<td>
<A HREF="http://.....asp?qid=<%=strThreadID%>">
<img src="http://....Attachbutton.jpg" width="75" height="25" BORDER="0" align=left>
</A>
</td>
</tr>

<tr>
<td>
<hr align=left>
</td>
</tr>
<%End If%>


<TR>
<TD align=center>
<INPUT TYPE="SUBMIT" NAME="send" VALUE="UPDATE" Class="button">
</TD>
</TR>
</TABLE>
</FORM>

=====================================
No matter what I try. It still allow user enter empty value to the table.

What seems to be wrong here?

Last edited by Discusman : February 2nd, 2005 at 11:13 AM.

Reply With Quote
  #12  
Old February 2nd, 2005, 11:18 AM
Discusman Discusman is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 346 Discusman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 2 h 38 m 12 sec
Reputation Power: 0
User Validation Update...

I have created a new ASP page with the same exact form that I listed in my previous post.

It works fine with the validate() function when I removed all the database connection on the page.

It stops working after I add the database connection to the page.

This is User Post Modify page, so the "Subject" and "Comment" fields are prefilled with data that retrieved from the database.
I simply use the response.write strSubject and strComment to prefill the text input fields.

Now it seems preventing the validation from working properly.
What is my doing wrong?
Thanks for the help.

Reply With Quote
  #13  
Old February 2nd, 2005, 01:11 PM
Discusman Discusman is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 346 Discusman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 2 h 38 m 12 sec
Reputation Power: 0
It doesn't work with Textarea Field

<script language="JavaScript">
function validate()
{
if (document.ModifyMessageSend.comment.value=="")
{

alert("Comment Must contain a value");
return false;
}
else
{
if (document.ModifyMessageSend.subject.value == "")
{
alert("Subject Must contain a Value");
return false;
}
else
{ return true; }
}
}
</script>




<TEXTAREA NAME="comment" ROWS = "13" COLS = "87">
<%'Response.Write strContent%></TEXTAREA>

<INPUT TYPE="SUBMIT" VALUE="UPDATE">


<FORM NAME="ModifyMessageSend" ACTION="http://.....asp"
onSubmit="return validate();" METHOD="POST">






<TEXTAREA NAME="comment" ROWS = "13" COLS = "87">
<%'Response.Write strContent%></TEXTAREA>

<INPUT TYPE="SUBMIT" VALUE="UPDATE">



</FORM>

The javascript doesn't validate the text area.

Reply With Quote
  #14  
Old February 2nd, 2005, 01:27 PM
lewy's Avatar
lewy lewy is offline
Alter Ego Wizard
ASP Free Specialist (4000 - 4499 posts)
 
Join Date: Jun 2004
Location: Edinburg Tx
Posts: 4,381 lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)lewy User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 1009 Folding Title: Novice Folder
Time spent in forums: 1 Month 1 Week 1 Day 23 h 7 m 43 sec
Reputation Power: 1488
Adding database fields don't matter if your form is correct.
If you are using textarea use something like this:
Code:
<html>
  <head>
  <script language="JavaScript">
  function validate()
  {
    if (document.main.subject.value=="")
    { 
  	 
  	 alert("Subject Must contain a value");
  	 return false;
    }
    else
  	{ 
  	  if (document.main.comment.value == "")
  	  { 
  		 alert("Comment Must contain a Value");
  	 return false;
  	  }
  	  else
  	   { return true; }
  	}
  }
  </script>
  </head>
  
  <body>
  <form name="main" action="" onSubmit="return validate();">
  <input type="text" name="subject" size="20">
  <br>
  <TEXTAREA NAME="comment" ROWS = "13" COLS = "87"></textarea>
  <br>
  <input type="submit" value="Update">
  </form>
  </body>
  </html>

I tested it and it works.
If it doesn't work, post all your relevant code. Maybe you aren't closing a tag somewher.

Reply With Quote