blank form submits

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 0utlawza
    New Member
    • Mar 2009
    • 3

    blank form submits

    Hi Guys

    It seems i posted this in the incorrect topic, so i am reposting here.

    Please excuse the Newbie question. I am not really a programmer so excuse me if i dont clarify my point correctly. I am trying to debug an ex-employee's web code and seem to sinking here. Let me try to explain.

    We are receiving few blank submit forms via a handful of clients websites. Ordinarily i would not stress too much as it is less that 5% of the form submits that are failing. However, seeing as we are looking after the clients SEM (search engine marketing) and the clients are getting charged for the submits (in a round about kinda way).I was informed by the miscreant that the blank form submits are due to client machines that do not have java installed or enabled in the browser. Now this does sound plausible to me, but very convenient.

    Below is the code i am looking at
    Code:
    <script language="javascript" type="text/javascript">
    function Validation(form){
    
    if (form.name.value == ""){
    alert("Please enter 'First Name'.");
    form.name.focus();
    return false;}
    
    var email = form.email.value;
    if (email==""){
    alert ("Please enter E-mail Address.");
    form.email.focus();
    return false;}
    if (email.length >0) {
    i=email.indexOf("@")
    j=email.indexOf(".",i)
    k=email.indexOf(",")
    kk=email.indexOf(" ")
    jj=email.lastIndexOf(".")+1
    len=email.length
    if ((i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3)) {
    }
    else {
    alert("Please enter an exact email address.\n" +
    email+ " is invalid.");
    return false;
    }
    }
    
    if (form.daycontactno.value == ""){
    alert("Please enter 'Contact No'.");
    form.daycontactno.focus();
    return false;}
    
    return true;
    }
    </script>

    And the form portion:

    Code:
    <p>Fields marked with * are mandatory</p>
    <form action="feedback.asp" method="post" name="form" onsubmit="return Validation(this)">
    <table width="96%" border="0" cellspacing="0" cellpadding="3">
    <tr>
    <td width="43%">First Name(s): *</td>
    <td width="57%"><label>
    <input type="text" name="name" id="name" style="width: 190px;"/>
    </label></td>
    </tr>
    <tr>
    <td>Last Name:</td>
    <td><input type="text" name="lastname" id="lastname" style="width: 190px;"/></td>
    </tr>
    <tr>
    <td>Email address: *</td>
    <td><input type="text" name="email" id="email" style="width: 190px;"/></td>
    </tr>
    <tr>
    <td>Tel: *</td>
    <td><input type="text" name="daycontactno" id="daycontactno" style="width: 190px;"/></td>
    </tr>
    <tr>
    <td>Mobile or other contact number:</td>
    <td><input type="text" name="mobileother" id="mobileother" style="width: 190px;"/></td>
    </tr>
    <tr>
    <td>Query:</td>
    <td><textarea name="query" id="query" style="width: 190px;"></textarea></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><label>
    <input type="submit" name="submit" id="submit" value="Submit" />
    </label></td>
    </tr>
    </table>
    </form>
    Any improvements or suggestion welcomed.

    TIA

    T
    Last edited by Dormilich; Mar 12 '09, 12:03 PM. Reason: added [code] tags
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Well, seeing that they are complaining that the submits are happening since the users do not have JavaScript enabled (and not the more obvious reason: the users are submitting the page with no information)... .you could force them to enable JavaScript before viewing your page.

    To do this, add <noscript> tags to your html.
    The content within the <noscript> tag will be displayed if JavaScript is disabled or not supported by the browser.

    For example:

    Code:
    <noscript>
    <div style="width:50%; margin-left: auto; margin-right:auto; background-color:#C0000; color:white; font-size: 22px;">
        In order to access this web site you must have JavaScript enabled.
    </div>
    </noscript>
    
    <!-- Your regular web content goes here -->
    Now, of course, you can place nicer HTML in in the <noscript> tag...
    But I think you get the point


    -Frinny

    Comment

    • 0utlawza
      New Member
      • Mar 2009
      • 3

      #3
      excellent. I will insert this into the html code and see what sort of response i get back from the client.

      Thanks

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        to really force them to use javaScript, you could go as far as omitting the submit button in the HTML code and add it via JavaScript.
        like
        Code:
        function makeSubmit()
        {
            // create the input element
            var inp = document.createElement("input");
            // further generation code
            document.getElementById("your_form_id").appendChild(inp);
        }
        
        window.addEventListener("load", makeSubmit, false);
        // use addEvent() function (=> google) for cross browser compatibility

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Ok that's a little bit mean!
          And not to mention confusing to the end user!

          A message should at least be displayed informing them that they need to enable JavaScript!

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            at least it makes sure, that you don't submit unchecked forms (of course the "please use javaScript" notification is required anyway). If you call that mean.....

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              You should validate on the server-side too, so if someone has JavaScript disabled, it will display error messages when they submit.

              Comment

              Working...