Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

FORM : Required fields

Options
  • 12-02-2006 9:11pm
    #1
    Registered Users Posts: 1,667 ✭✭✭


    This gives me an headache. I tried this script on IE and Firefox, it works except on Firefox it still sends out the form action. I am working on a credit card payment page, so on Firefox it does give the user warning to field the required fill but once click OK, it sends out the data.
    <HTML>
    <HEAD>
    <TITLE>Required Fields</TITLE>
    <SCRIPT>
    function validate() {
    mNv=mainform.Name.value;
    if (mNv=='') {
    alert('Your name is a required field. Please try again.');
    event.returnValue=false;
    }
    if (!(mainform.Sex[0].checked || mainform.Sex[1].checked)) {
    alert('Your sex is a required field. Please try again.');
    event.returnValue=false;
    }
    }
    </SCRIPT>
    </HEAD>
    <BODY>
    <FORM NAME="mainform" ACTION="http://yourdomainhere/cgi-bin/post-query" METHOD="post" onsubmit="validate();">
    <INPUT TYPE="TEXT" NAME="Name" >Please enter your name (required)
    <BR>
    <INPUT TYPE="RADIO" NAME="Sex" VALUE="Male">Male
    <INPUT TYPE="RADIO" NAME="Sex" VALUE="Female">Female
    <BR>
    <INPUT TYPE="SUBMIT">
    </FORM>
    </BODY>
    </HTML>
    

    am wondering if anyone has better script to do this?


Comments

  • Closed Accounts Posts: 7,145 ✭✭✭DonkeyStyle \o/


    Well you could just hand off that task to the form handler script... which is probably better anyway since if someone is determined enough to bypass these 'required fields' then a bit of javascript isn't going to stop them.
    This is assuming you've actually got access to it though.


  • Registered Users Posts: 1,667 ✭✭✭MartMax


    i'm basically creating a form that collect credit card details to be passed to my merchant gateway. i only need a simple script that ensure all required data is sent to the server. i don't need bullet proof script, a SSL cert is already in place, not that i say it's gonna be 100% secured transmission.

    SORTED, found another working script.
    <script language="JavaScript" type="text/javascript">
    <!--
    function validateForm() {
     var name = document.myForm.username.value;
     var email = document.myForm.email.value;
     if (name == "") {
       alert("Please fill in your name.");
       return false;
     }
     if (email == "") {
       alert("Please fill in your email address.");
       return false;
     }
     return true;
    }
    //-->
    </script>
    <form action="blah.cgi" name="myForm" method="post"
         onSubmit="return validateForm();">
    Your name: <input type="text" name="username"> *<br>
    Email address: <input type="text" name="email"> *<br>
    Phone Number: <input type="text" name="phone"><br>
    <input type="submit" name="submit" value="Submit">
    </form>
    <p>(* indicates a required field)</p>
    


Advertisement