Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Is this possible?

  1. #1
    Join Date
    Nov 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default form validation

    Hey guys.
    Is there a javascript or other serverside script out there that will allow me to check and see if a required form element has a certain value?

    Here is my current code, it might give you a lead to what I mean:

    HTML Code:
    <form action="netxpage.php">
    ID:&nbsp;&nbsp;<input type="text" name="id"><br>
    // This field requires the validation, it must have a certain value in it for the
    //user to procede.
    <input type="submit" value="Continue">
    </form>
    Last edited by bjf98; 01-22-2008 at 08:59 PM.

  2. #2
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    yes of course. would you prefer it javascript(client) or php(server) (i would choose php, almost impossible to trick)? what do you want the syntax to be? e.g. xxx-xxx-xxx or xxxxxxxxx or only letters or only numbers or a combination of both?
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  3. #3
    Join Date
    Nov 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    How about php with a santax of xxxxxxxxx and only #'s.

  4. #4
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    Edit: script changed

    your form(must be .php):
    HTML Code:
    <form action="validate.php" method="post">
    <div style="color: red"><?php if ($error) { echo $error; } ?></div>
    ID:&nbsp;&nbsp;<input type="text" name="id"><br>
    <input type="submit" value="Continue">
    </form>
    validate.php:
    PHP Code:
    <?php
    $nextpage
    =""//the page to go to if there are no errors e.g. nextpage.php
    $formpage=""//the form page
    $string $_POST['id'];
    if (
    $string==null) { 
        
    $error "You did not enter anything.";
    } else {
        if (!
    eregi('^[0-9]{9}$'$string)) {
            
    $error "'$string' is not a valid id.";
        }
    }
    if (
    $error == null) {
        echo 
    "<script type=\"text/javascript\">
        window.location=\""
    .$nextpage."\";
        </script>
        <p>If you were not redirected click <a href=\""
    .$nextpage."\">here.</a></p>";
    } else {
        include(
    $formpage);
    }
    ?>
    Last edited by Master_script_maker; 01-19-2008 at 09:24 PM.
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  5. #5
    Join Date
    Nov 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Tks!
    Uh.. where does the valid id get entered in the script?

  6. #6
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    do you mean where the script gets the content of the ip input, or the form?
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  7. #7
    Join Date
    Nov 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    the id that has to match the one the user enters

  8. #8
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    i think i misinterpreted your fist post. you wanted to use the id to login?
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  9. #9
    Join Date
    Mar 2007
    Location
    Tarboro, NC
    Posts
    290
    Thanks
    8
    Thanked 2 Times in 2 Posts

    Default

    Does he just want something like:

    Code:
    $id=$_POST['id'];
    
    if ($id=="1232343") {
    print("
    <head>
    <script type=\"javascript\">
    window.location='nextpage.html';
    </script>
    <body>
    </body>");
    }
    
    else {
    print("
    <head>
    <script type=\"javascript\">
    setTimeOut("window.location='javascript.go:history(-1)'",5000);
    </script>
    <body>
    ID wrong, please try again.
    </body>
    }
    Then a form as so:

    Code:
    <form action="thephp.php" method="post">
    <input type="text" name="id" value="Type ID in here.">
    <input type="submit" value="Check ID">
    </form>
    That is very simple, should work just fine for 1, 2, 3, up to maybe 6 IDs but if more then you shouldn't use this method most likely.
    Also someone had best check to make sure the "javascript.go:history(-1) is right, I believe it is but I can't be sure.

    Tim

  10. #10
    Join Date
    Nov 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi Tim
    Tks for the script, but there seems to be a error in line 18.
    Here is the error code:
    Parse error: syntax error, unexpected T_STRING in /***/****/***/***/***/thephp.php on line 18

Bookmarks

Posting Permissions

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