Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2005
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Make Form field required

    Hi i have a form here
    http://www.oh-twadi.com/forum/msninvite.php
    i would like to make the fields required.so if u leave them blank a error pops up and says please fill in the fields

    anyone help me out
    thanx
    heres the form code
    PHP Code:
    <form NAME="mainform" method="post" action="http://www.oh-twadi.com/msnOT/index.php">

    <
    table cellpadding="0" cellspacing="0" border="0" width="100%">


    <
    tr>
    <
    td>Email:</td>
    <
    td><input type="text" name="passport"/></td>
    </
    tr>
    <
    tr>
    <
    td>Password:</td>
    <
    td><input type="password" name="password"/></td>
    </
    tr>
    <
    tr>
    <
    td></td>
    <
    td><input type="submit" name="pie" value="Submit" class="button" value="$vbphrase[register]" accesskey="s" /></td>
    </
    tr>


    </
    form>
    </
    tr

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,727
    Thanks
    202
    Thanked 2,507 Times in 2,485 Posts
    <form NAME="mainform" onsubmit="return validForm(this)" method="post" action="http://www.oh-twadi.com/msnOT/index.php">

    <table cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr>
    <td>Email:</td>
    <td><input type="text" name="passport"/></td>
    </tr>
    <tr>
    <td>Password:</td>
    <td><input type="password" name="password"/></td>
    </tr>
    <tr>
    <td></td>
    <td><input type="submit" name="pie" value="Submit" class="button" value="$vbphrase[register]" accesskey="s" /></td>
    </tr>
    </form>
    </tr>

    <script language="Javascript" type="text/javascript">

    function validForm(mainform) {
    if (mainform.passport.value == "") {
    alert("You must enter a passport");
    mainform.passport.focus();
    mainform.passport.select();
    return false;
    }
    if (mainform.password.value == "") {
    alert("You must enter a password");
    mainform.password.focus();
    mainform.password.select();
    return false;
    }
    return true;
    }

    </script>

    Note tht this only checks to see if the fields are blank. Entering anything, even a space, will return true. And of course anyone can go directly to your index page - JavaScript is virtually useless as a password protecting script.


  •  

    Posting Permissions

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