By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,200 Members | 1,668 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,200 IT Pros & Developers. It's quick & easy.

blank form submits

P: 3
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
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript">
  2. function Validation(form){
  3.  
  4. if (form.name.value == ""){
  5. alert("Please enter 'First Name'.");
  6. form.name.focus();
  7. return false;}
  8.  
  9. var email = form.email.value;
  10. if (email==""){
  11. alert ("Please enter E-mail Address.");
  12. form.email.focus();
  13. return false;}
  14. if (email.length >0) {
  15. i=email.indexOf("@")
  16. j=email.indexOf(".",i)
  17. k=email.indexOf(",")
  18. kk=email.indexOf(" ")
  19. jj=email.lastIndexOf(".")+1
  20. len=email.length
  21. if ((i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (len-jj<=3)) {
  22. }
  23. else {
  24. alert("Please enter an exact email address.\n" +
  25. email+ " is invalid.");
  26. return false;
  27. }
  28. }
  29.  
  30. if (form.daycontactno.value == ""){
  31. alert("Please enter 'Contact No'.");
  32. form.daycontactno.focus();
  33. return false;}
  34.  
  35. return true;
  36. }
  37. </script>

And the form portion:

Expand|Select|Wrap|Line Numbers
  1. <p>Fields marked with * are mandatory</p>
  2. <form action="feedback.asp" method="post" name="form" onsubmit="return Validation(this)">
  3. <table width="96%" border="0" cellspacing="0" cellpadding="3">
  4. <tr>
  5. <td width="43%">First Name(s): *</td>
  6. <td width="57%"><label>
  7. <input type="text" name="name" id="name" style="width: 190px;"/>
  8. </label></td>
  9. </tr>
  10. <tr>
  11. <td>Last Name:</td>
  12. <td><input type="text" name="lastname" id="lastname" style="width: 190px;"/></td>
  13. </tr>
  14. <tr>
  15. <td>Email address: *</td>
  16. <td><input type="text" name="email" id="email" style="width: 190px;"/></td>
  17. </tr>
  18. <tr>
  19. <td>Tel: *</td>
  20. <td><input type="text" name="daycontactno" id="daycontactno" style="width: 190px;"/></td>
  21. </tr>
  22. <tr>
  23. <td>Mobile or other contact number:</td>
  24. <td><input type="text" name="mobileother" id="mobileother" style="width: 190px;"/></td>
  25. </tr>
  26. <tr>
  27. <td>Query:</td>
  28. <td><textarea name="query" id="query" style="width: 190px;"></textarea></td>
  29. </tr>
  30. <tr>
  31. <td>&nbsp;</td>
  32. <td><label>
  33. <input type="submit" name="submit" id="submit" value="Submit" />
  34. </label></td>
  35. </tr>
  36. </table>
  37. </form>
Any improvements or suggestion welcomed.

TIA

T
Mar 12 '09 #1
Share this Question
Share on Google+
6 Replies


Frinavale
Expert Mod 5K+
P: 9,731
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:

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


-Frinny
Mar 12 '09 #2

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

Thanks
Mar 12 '09 #3

Dormilich
Expert Mod 5K+
P: 8,639
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
Expand|Select|Wrap|Line Numbers
  1. function makeSubmit()
  2. {
  3.     // create the input element
  4.     var inp = document.createElement("input");
  5.     // further generation code
  6.     document.getElementById("your_form_id").appendChild(inp);
  7. }
  8.  
  9. window.addEventListener("load", makeSubmit, false);
  10. // use addEvent() function (=> google) for cross browser compatibility
Mar 12 '09 #4

Frinavale
Expert Mod 5K+
P: 9,731
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!
Mar 12 '09 #5

Dormilich
Expert Mod 5K+
P: 8,639
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.....
Mar 12 '09 #6

acoder
Expert Mod 15k+
P: 16,027
You should validate on the server-side too, so if someone has JavaScript disabled, it will display error messages when they submit.
Mar 12 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.