ON SUBMIT, check text for 'ERRORS' 
Author Message
 ON SUBMIT, check text for 'ERRORS'

I want to check text entered in form fields for comma's and apostraphes as
SQL server rejects these characters.  I have no idea how to code the ON
SUBMIT or whether this is the best way to go about.  Example code would be
much appreciated.




Fri, 12 Jul 2002 03:00:00 GMT  
 ON SUBMIT, check text for 'ERRORS'
try:

for i=1 to len(string)
    if ((mid(string,i,1) = ",") or (mid(string,i,1)="'")) then
   ' your error code goes here....
  end if
next



Quote:
> I want to check text entered in form fields for comma's and apostraphes as
> SQL server rejects these characters.  I have no idea how to code the ON
> SUBMIT or whether this is the best way to go about.  Example code would be
> much appreciated.





Fri, 12 Jul 2002 03:00:00 GMT  
 ON SUBMIT, check text for 'ERRORS'
This is a little difficult to follow.  Is this part of an on submit routine
or something else?  Has anyone got any simple, sample code that checks the
entry in a text box either as soon as the text is entered or on submit??



Quote:
> try:

> for i=1 to len(string)
>     if ((mid(string,i,1) = ",") or (mid(string,i,1)="'")) then
>    ' your error code goes here....
>   end if
> next



> > I want to check text entered in form fields for comma's and apostraphes
as
> > SQL server rejects these characters.  I have no idea how to code the ON
> > SUBMIT or whether this is the best way to go about.  Example code would
be
> > much appreciated.





Fri, 12 Jul 2002 03:00:00 GMT  
 ON SUBMIT, check text for 'ERRORS'
There is nothing wrong with Dieter's code!

I myself use this handy vb function in my ASP
to prevent my code from  breaking!

In your ASP just call this function before you save your field to the database!

----------------------------------
function FormatStringForSQL(text)
'Note:
'Returns a string that is formatted for SQL use
'Replaces ' with '' and empty string with NULL

  if text = "" then
    FormatStringForSql= "null"
  else
    FormatStringForSql = "'"&trim(Replace(text,"'","''"))&"'"
  end if
end function

Your HTML!
---------------
<html>
<head>
 <title>Untitled</title>
</head>
<script language="JavaScript1.2">
  <!--
  errorMessageArray = new Array(1)
  errorMessageArray[0] = "Error!......\nYou stupid user!";

  function validate()
  {
   if ((document.theform.field1.value.indexOf("'") !=
-1)&&(document.theform.field1.value.indexOf(",") != -1))
    {
    alert(errorMessageArray[0]);
    document.theform.field1.focus();
    return false;
    }
    //Here everthing is fine!
    return true;
  }
  //-->
</script>
<body>
<form method="post" action="edit.asp" name="theform" onsubmit="javascript:
return validate()">
*Field1 :<input type="text" name="field1"><br>
<input type="submit" name="submit" value="submit"><input type="Reset">
</form>
</body>
</html>

Hope this helps also!

Coenie Richards

Quote:

> This is a little difficult to follow.  Is this part of an on submit routine
> or something else?  Has anyone got any simple, sample code that checks the
> entry in a text box either as soon as the text is entered or on submit??




> > try:

> > for i=1 to len(string)
> >     if ((mid(string,i,1) = ",") or (mid(string,i,1)="'")) then
> >    ' your error code goes here....
> >   end if
> > next



> > > I want to check text entered in form fields for comma's and apostraphes
> as
> > > SQL server rejects these characters.  I have no idea how to code the ON
> > > SUBMIT or whether this is the best way to go about.  Example code would
> be
> > > much appreciated.





Fri, 12 Jul 2002 03:00:00 GMT  
 ON SUBMIT, check text for 'ERRORS'
Thanks for the help, Im sure all the code here is fine.  I want the VB
Script equivalent though, sorry to be a pain in the bum.


Quote:
> There is nothing wrong with Dieter's code!

> I myself use this handy vb function in my ASP
> to prevent my code from  breaking!

> In your ASP just call this function before you save your field to the
database!

> ----------------------------------
> function FormatStringForSQL(text)
> 'Note:
> 'Returns a string that is formatted for SQL use
> 'Replaces ' with '' and empty string with NULL

>   if text = "" then
>     FormatStringForSql= "null"
>   else
>     FormatStringForSql = "'"&trim(Replace(text,"'","''"))&"'"
>   end if
> end function

> Your HTML!
> ---------------
> <html>
> <head>
>  <title>Untitled</title>
> </head>
> <script language="JavaScript1.2">
>   <!--
>   errorMessageArray = new Array(1)
>   errorMessageArray[0] = "Error!......\nYou stupid user!";

>   function validate()
>   {
>    if ((document.theform.field1.value.indexOf("'") !=
> -1)&&(document.theform.field1.value.indexOf(",") != -1))
>     {
>     alert(errorMessageArray[0]);
>     document.theform.field1.focus();
>     return false;
>     }
>     file://Here everthing is fine!
>     return true;
>   }
>   file://-->
> </script>
> <body>
> <form method="post" action="edit.asp" name="theform" onsubmit="javascript:
> return validate()">
> *Field1 :<input type="text" name="field1"><br>
> <input type="submit" name="submit" value="submit"><input type="Reset">
> </form>
> </body>
> </html>

> Hope this helps also!

> Coenie Richards


> > This is a little difficult to follow.  Is this part of an on submit
routine
> > or something else?  Has anyone got any simple, sample code that checks
the
> > entry in a text box either as soon as the text is entered or on submit??




> > > try:

> > > for i=1 to len(string)
> > >     if ((mid(string,i,1) = ",") or (mid(string,i,1)="'")) then
> > >    ' your error code goes here....
> > >   end if
> > > next



> > > > I want to check text entered in form fields for comma's and
apostraphes
> > as
> > > > SQL server rejects these characters.  I have no idea how to code the
ON
> > > > SUBMIT or whether this is the best way to go about.  Example code
would
> > be
> > > > much appreciated.





Fri, 12 Jul 2002 03:00:00 GMT  
 ON SUBMIT, check text for 'ERRORS'
That is VBScript? [ok theres html etc in there too but even so.]


Fri, 12 Jul 2002 03:00:00 GMT  
 ON SUBMIT, check text for 'ERRORS'
Someone else sent me this last week. I'm using it to keep the
formatting (single quotes specifically) so it will submit to the
database and still look right to my users later.

Quote:
> > Use this in the script that inserts the data into the table.

> > <%
> >    t1 = Request("fieldname")
> >    t1 = replace(t1,Chr(39),"Chr(39)")
> >    t1 = replace(t1,Chr(34),"Chr(34)")
> >    t1 = replace(t1,Chr(10),"Chr(10)")
> > %>

> > Use this in any script that displays the contents of that table.

> > <%
> >    t1 = RS("fieldname")
> >    t1 = replace(t1,"Chr(39)",Chr(39))
> >    t1 = replace(t1,"Chr(34)",Chr(34))
> >    t1 = replace(t1,"Chr(10)",Chr(10))
> > %>

The only problem I'm having is using the first chunk of code to save
the data to the database and the second half later in the page to
present the data (with the same variables) at the end of the page. Even
so, this does most of what I want...may help you.



- Show quoted text -

Quote:
> Thanks for the help, Im sure all the code here is fine.  I want the VB
> Script equivalent though, sorry to be a pain in the bum.



> > There is nothing wrong with Dieter's code!

> > I myself use this handy vb function in my ASP
> > to prevent my code from  breaking!

> > In your ASP just call this function before you save your field to
the
> database!

> > ----------------------------------
> > function FormatStringForSQL(text)
> > 'Note:
> > 'Returns a string that is formatted for SQL use
> > 'Replaces ' with '' and empty string with NULL

> >   if text = "" then
> >     FormatStringForSql= "null"
> >   else
> >     FormatStringForSql = "'"&trim(Replace(text,"'","''"))&"'"
> >   end if
> > end function

> > Your HTML!
> > ---------------
> > <html>
> > <head>
> >  <title>Untitled</title>
> > </head>
> > <script language="JavaScript1.2">
> >   <!--
> >   errorMessageArray = new Array(1)
> >   errorMessageArray[0] = "Error!......\nYou stupid user!";

> >   function validate()
> >   {
> >    if ((document.theform.field1.value.indexOf("'") !=
> > -1)&&(document.theform.field1.value.indexOf(",") != -1))
> >     {
> >     alert(errorMessageArray[0]);
> >     document.theform.field1.focus();
> >     return false;
> >     }
> >     file://Here everthing is fine!
> >     return true;
> >   }
> >   file://-->
> > </script>
> > <body>
> > <form method="post" action="edit.asp" name="theform"

onsubmit="javascript:

- Show quoted text -

Quote:
> > return validate()">
> > *Field1 :<input type="text" name="field1"><br>
> > <input type="submit" name="submit" value="submit"><input
type="Reset">
> > </form>
> > </body>
> > </html>

> > Hope this helps also!

> > Coenie Richards


> > > This is a little difficult to follow.  Is this part of an on
submit
> routine
> > > or something else?  Has anyone got any simple, sample code that
checks
> the
> > > entry in a text box either as soon as the text is entered or on
submit??




> > > > try:

> > > > for i=1 to len(string)
> > > >     if ((mid(string,i,1) = ",") or (mid(string,i,1)="'")) then
> > > >    ' your error code goes here....
> > > >   end if
> > > > next



> > > > > I want to check text entered in form fields for comma's and
> apostraphes
> > > as
> > > > > SQL server rejects these characters.  I have no idea how to
code the
> ON
> > > > > SUBMIT or whether this is the best way to go about.  Example
code
> would
> > > be
> > > > > much appreciated.



Sent via Deja.com http://www.deja.com/
Before you buy.


Sat, 13 Jul 2002 03:00:00 GMT  
 ON SUBMIT, check text for 'ERRORS'
What part the ASP or Java script?
The ASP (server side) is VB script (that you should know!)
If you are troubled about the Java script (client side), then just look at
Dieter's code!
Quote:

> Thanks for the help, Im sure all the code here is fine.  I want the VB
> Script equivalent though, sorry to be a pain in the bum.



> > There is nothing wrong with Dieter's code!

> > I myself use this handy vb function in my ASP
> > to prevent my code from  breaking!

> > In your ASP just call this function before you save your field to the
> database!

> > ----------------------------------
> > function FormatStringForSQL(text)
> > 'Note:
> > 'Returns a string that is formatted for SQL use
> > 'Replaces ' with '' and empty string with NULL

> >   if text = "" then
> >     FormatStringForSql= "null"
> >   else
> >     FormatStringForSql = "'"&trim(Replace(text,"'","''"))&"'"
> >   end if
> > end function

> > Your HTML!
> > ---------------
> > <html>
> > <head>
> >  <title>Untitled</title>
> > </head>
> > <script language="JavaScript1.2">
> >   <!--
> >   errorMessageArray = new Array(1)
> >   errorMessageArray[0] = "Error!......\nYou stupid user!";

> >   function validate()
> >   {
> >    if ((document.theform.field1.value.indexOf("'") !=
> > -1)&&(document.theform.field1.value.indexOf(",") != -1))
> >     {
> >     alert(errorMessageArray[0]);
> >     document.theform.field1.focus();
> >     return false;
> >     }
> >     file://Here everthing is fine!
> >     return true;
> >   }
> >   file://-->
> > </script>
> > <body>
> > <form method="post" action="edit.asp" name="theform" onsubmit="javascript:
> > return validate()">
> > *Field1 :<input type="text" name="field1"><br>
> > <input type="submit" name="submit" value="submit"><input type="Reset">
> > </form>
> > </body>
> > </html>

> > Hope this helps also!

> > Coenie Richards


> > > This is a little difficult to follow.  Is this part of an on submit
> routine
> > > or something else?  Has anyone got any simple, sample code that checks
> the
> > > entry in a text box either as soon as the text is entered or on submit??




> > > > try:

> > > > for i=1 to len(string)
> > > >     if ((mid(string,i,1) = ",") or (mid(string,i,1)="'")) then
> > > >    ' your error code goes here....
> > > >   end if
> > > > next



> > > > > I want to check text entered in form fields for comma's and
> apostraphes
> > > as
> > > > > SQL server rejects these characters.  I have no idea how to code the
> ON
> > > > > SUBMIT or whether this is the best way to go about.  Example code
> would
> > > be
> > > > > much appreciated.





Sat, 13 Jul 2002 03:00:00 GMT  
 ON SUBMIT, check text for 'ERRORS'
Still stuck, Im a basic user and this is confusing me a touch....Can someone
please look at this code and suggest a solution.  I'm sure someone has come
accross this particular problem before....

<HTML>
<HEAD><TITLE>Simple Validation</TITLE>
<SCRIPT LANGUAGE="VBScript">
<!--
Sub Submit_OnClick
  Dim TheForm
  Set TheForm = Document.ValidForm

****SOME CODE TO GO THROUGH THE STRING AND FIND EITHER A ' OR A " and THEN

  MsgBox "Please type question again without punctuation"
    Else
      MsgBox "Thank you."
    End If
  Else
    MsgBox "TEST"
  End If
End Sub
-->
</SCRIPT>
</HEAD>
<BODY>
<H3>Simple Validation</H3><HR>
<FORM NAME="ValidForm">
Enter your question here:
<INPUT NAME="Text1" SIZE="10">
<INPUT NAME="Submit" TYPE="BUTTON" VALUE="Submit">
</FORM>
</BODY>
</HTML>



Sat, 13 Jul 2002 03:00:00 GMT  
 ON SUBMIT, check text for 'ERRORS'
The lines marked *** I made or modified!

<HTML>
  <HEAD><TITLE>Simple Validation</TITLE>
  <SCRIPT LANGUAGE="VBScript">
  <!--
  Sub Submit_OnClick
    Dim TheForm
    Set TheForm = Document.ValidForm

***      if InStr(TheForm.Text1.value, "'") <> 0 then
        MsgBox "Please type question again without punctuation"
      Else
        MsgBox "Thank you."
      End If
  End Sub
  -->
  </SCRIPT>
  </HEAD>
  <BODY>
  <H3>Simple Validation</H3><HR>
***  <FORM NAME="ValidForm" onsubmit="submit_Onclick()">
  Enter your question here:
  <INPUT NAME="Text1" SIZE="10">
  <INPUT NAME="Submit" TYPE="BUTTON" VALUE="Submit">
  </FORM>
  </BODY>
  </HTML>

Quote:

> Still stuck, Im a basic user and this is confusing me a touch....Can someone
> please look at this code and suggest a solution.  I'm sure someone has come
> accross this particular problem before....

> <HTML>
> <HEAD><TITLE>Simple Validation</TITLE>
> <SCRIPT LANGUAGE="VBScript">
> <!--
> Sub Submit_OnClick
>   Dim TheForm
>   Set TheForm = Document.ValidForm

> ****SOME CODE TO GO THROUGH THE STRING AND FIND EITHER A ' OR A " and THEN

>   MsgBox "Please type question again without punctuation"
>     Else
>       MsgBox "Thank you."
>     End If
>   Else
>     MsgBox "TEST"
>   End If
> End Sub
> -->
> </SCRIPT>
> </HEAD>
> <BODY>
> <H3>Simple Validation</H3><HR>
> <FORM NAME="ValidForm">
> Enter your question here:
> <INPUT NAME="Text1" SIZE="10">
> <INPUT NAME="Submit" TYPE="BUTTON" VALUE="Submit">
> </FORM>
> </BODY>
> </HTML>



Sat, 13 Jul 2002 03:00:00 GMT  
 ON SUBMIT, check text for 'ERRORS'
This is Great, thanks Coenie

It goes a bit funny if you replace the ' with a " - nothing happens at all??
Anyone know why this is?


Quote:
> The lines marked *** I made or modified!

> <HTML>
>   <HEAD><TITLE>Simple Validation</TITLE>
>   <SCRIPT LANGUAGE="VBScript">
>   <!--
>   Sub Submit_OnClick
>     Dim TheForm
>     Set TheForm = Document.ValidForm

> ***      if InStr(TheForm.Text1.value, "'") <> 0 then
>         MsgBox "Please type question again without punctuation"
>       Else
>         MsgBox "Thank you."
>       End If
>   End Sub
>   -->
>   </SCRIPT>
>   </HEAD>
>   <BODY>
>   <H3>Simple Validation</H3><HR>
> ***  <FORM NAME="ValidForm" onsubmit="submit_Onclick()">
>   Enter your question here:
>   <INPUT NAME="Text1" SIZE="10">
>   <INPUT NAME="Submit" TYPE="BUTTON" VALUE="Submit">
>   </FORM>
>   </BODY>
>   </HTML>


> > Still stuck, Im a basic user and this is confusing me a touch....Can
someone
> > please look at this code and suggest a solution.  I'm sure someone has
come
> > accross this particular problem before....

> > <HTML>
> > <HEAD><TITLE>Simple Validation</TITLE>
> > <SCRIPT LANGUAGE="VBScript">
> > <!--
> > Sub Submit_OnClick
> >   Dim TheForm
> >   Set TheForm = Document.ValidForm

> > ****SOME CODE TO GO THROUGH THE STRING AND FIND EITHER A ' OR A " and
THEN

> >   MsgBox "Please type question again without punctuation"
> >     Else
> >       MsgBox "Thank you."
> >     End If
> >   Else
> >     MsgBox "TEST"
> >   End If
> > End Sub
> > -->
> > </SCRIPT>
> > </HEAD>
> > <BODY>
> > <H3>Simple Validation</H3><HR>
> > <FORM NAME="ValidForm">
> > Enter your question here:
> > <INPUT NAME="Text1" SIZE="10">
> > <INPUT NAME="Submit" TYPE="BUTTON" VALUE="Submit">
> > </FORM>
> > </BODY>
> > </HTML>



Sat, 13 Jul 2002 03:00:00 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. check if server's online before submitting a form

2. Runtime error ''800a01b6''

3. 'submit' button problem

4. Automatically Emailing upon 'submit'

5. error 'ASP 0115' Unexpected error

6. 'text' property is read only error

7. Run-time error '429': ActiveX component can't create object

8. client found response content type of 'text/html', but expected 'text/xml'. error

9. Run-time error '-2147417846 (8001010a)': Automation error (error 440)

10. Run-time error '-2147417846 (8001010a)': Automation error (error 440)

11. Can't check the text and number

12. Can't check the text and number

 

 
Powered by phpBB® Forum Software