slitaz-pizza rev 93
lib/functions.js: desc should not be executable (again)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Mon Jan 28 11:46:36 2013 +0100 (2013-01-28) |
parents | e4bf1581a71b |
children | 5fc8986fd0a0 |
files | web/lib/functions.js |
line diff
1.1 --- a/web/lib/functions.js Mon Jan 28 09:34:12 2013 +0100 1.2 +++ b/web/lib/functions.js Mon Jan 28 11:46:36 2013 +0100 1.3 @@ -1,30 +1,33 @@ 1.4 // SliTaz Pizza Javascript functions. 1.5 // 1.6 1.7 +function charactersOK(field, name) { 1.8 + var str = "`!@#$%^&*()+=[]\\\';,./{}|\":<>?"; 1.9 + if(document.forms["pizza"][field].value == "") { 1.10 + alert("Please enter"+name); 1.11 + document.forms["pizza"][field].focus(); 1.12 + return false; 1.13 + } 1.14 + for (var i = 0; i < document.forms["pizza"][field].value.length; i++) { 1.15 + if (str.indexOf(document.forms["pizza"][field].value.charAt(i)) != -1) { 1.16 + alert ("Invalid "+name+".\n Please remove special characters."); 1.17 + document.forms["pizza"][field].focus(); 1.18 + return false; 1.19 + } 1.20 + } 1.21 + return true; 1.22 +} 1.23 + 1.24 // Check form to avoid empty values and bad email. 1.25 function checkForm() { 1.26 - if(document.forms["pizza"]["flavor"].value == "") 1.27 - { 1.28 - alert("Please enter SliTaz pizza flavor name"); 1.29 - document.forms["pizza"]["flavor"].focus(); 1.30 - return false; 1.31 - } else { 1.32 - var str = "!@#$%^&*()+=[]\\\';,./{}|\":<>?"; 1.33 - for (var i = 0; i < document.forms["pizza"]["flavor"].value.length; i++) { 1.34 - if (str.indexOf(document.forms["pizza"]["flavor"].value.charAt(i)) != -1) 1.35 - { 1.36 - alert ("Invalid Flavor name.\n Please remove special characters."); 1.37 - document.forms["pizza"]["desc"].focus(); 1.38 - return false; 1.39 - } 1.40 - } 1.41 - } 1.42 - if(document.forms["pizza"]["desc"].value == "") 1.43 - { 1.44 - alert("Please fill in the flavor description"); 1.45 - document.forms["pizza"]["desc"].focus(); 1.46 - return false; 1.47 - } 1.48 + if (!charactersOK("flavor", "pizza flavor name", 1.49 + "`!@#$%^&*()+=[]\\\';,./{}|\":<>?")) 1.50 + return false; 1.51 + if (!charactersOK("desc", "flavor description", 1.52 + "`!@#$%^&*()+=[]\\\';,./{}|\":<>?")) 1.53 + return false; 1.54 + if (!charactersOK("mail", "email address", "$`\\")) 1.55 + return false; 1.56 var x=document.forms["pizza"]["mail"].value; 1.57 var atpos=x.indexOf("@"); 1.58 var dotpos=x.lastIndexOf(".");