Results 1 to 6 of 6

Thread: Help filtering this

  1. #1

    Thread Starter
    Hyperactive Member zer0_flaw's Avatar
    Join Date
    Apr 2001
    Posts
    448

    Help filtering this

    This makes two boxes that users of the site can type into and submit. One is labeled "Nick" and the other is "Comment". My question is how do I limit it so the nick cannot be "bleh" and the comment can be no longer then 50 letters. Any help is GREATLY appreciated. Thanks in advance... here's the code:


    <form method="POST" action=addpost.php>Nick: <div align=center><input class=inputsb type=text name=n value=""></td></tr>
    <tr><td class=sbcomment>Comment: <div align=center><input type=text name=c limit=50 class=inputsb></td></tr>
    <tr><td class=sbcomment align=center>HTML is off.</td></tr><tr><td class=sbcomment><div align=center><input type=submit value=Submit class=inputsb></form>

  2. #2
    Lively Member
    Join Date
    May 2001
    Location
    Fredericton, NB, Canada
    Posts
    85
    The following section of Javascript/HTML should do the job for you.

    Code:
    <HTML>
    <HEAD>
    <script language="javascript">
    function checkForm(){
         if (document.frmPost.n.value != "bleh"){
                 document.frmPost.submit();
          }
         else {
              alert('Sorry Nick can not equal bleh');
          }
    }
    </script>
    </HEAD>
    <BODY>
    
    <form method="POST" action="addpost.php" name="frmPost">
    <table>
    <tr>
    <td>
    Nick: 
    <input class="inputsb" type="text" name="n" value="">
    </td>
    </tr>
    <tr>
    <td class="sbcomment">
    Comment:
    <input type="text" name="c" size="50" class="inputsb>
    </td>
    </tr>
    <tr>
    <td class="sbcomment" align="center">
    <input type="button" onclick="checkForm()">Submit</input>
    </td>
    </tr>
    </table>
    </form>
    
    </body>
    </HTML>

  3. #3
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    This makes two boxes that users of the site can type into and submit. One is labeled "Nick" and the other is "Comment". My question is how do I limit it so the nick cannot be "bleh" and the comment can be no longer then 50 letters. Any help is GREATLY appreciated. Thanks in advance... here's the code:
    You really need to validate this on the server, too, though...
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  4. #4
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    yeah, i say always validate it on the server. anyone can get around it otherwise. just look at what happened on this site with the custom statuses!

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  5. #5
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205

    Two things...

    <input type="text" name="c" size="50" class="inputsb>
    From Neil

    I juist wanted someone to verify that setting the size attribute of a text-box actually limits the input length? I was under the impression that this merely limited the viewable area. Am I mistaken? And is this the same for NS & IE??

    The other - zer0, did you want to specifically prevent 'bleh' as an input, or were you looking to prevent a garbage entry??
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

  6. #6
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    maxlength=50 should limit the number of characters a user can type into the box. It's by no means secure, though.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width