{"id":3271,"date":"2014-03-21T18:28:39","date_gmt":"2014-03-21T18:28:39","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/21\/mail-not-sending-after-valiidation-collection-of-common-programming-errors\/"},"modified":"2014-03-21T18:28:39","modified_gmt":"2014-03-21T18:28:39","slug":"mail-not-sending-after-valiidation-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/21\/mail-not-sending-after-valiidation-collection-of-common-programming-errors\/","title":{"rendered":"Mail not sending after valiidation-Collection of common programming errors"},"content":{"rendered":"<p>this is an expanded version of a question I asked last night, but with much more detail. All my php files and js file are in a folder called js one level down from my html pages. I have a contact form that mails the content of my shopping cart and form inputs to my email using php mail. I am validating the form on submit:<\/p>\n<pre><code>\n<\/code><\/pre>\n<p>with this submit button:<\/p>\n<pre><code>\n<\/code><\/pre>\n<p>The validation works as it should, here is the code (validate.js):<\/p>\n<pre><code>function setSelRange(inputEl, selStart, selEnd) { \nif (inputEl.setSelectionRange) { \ninputEl.focus(); \ninputEl.setSelectionRange(selStart, selEnd); \n} else if (inputEl.createtextRange) { \nvar range = inputEl.createtextRange(); \nrange.collapse(true); \nrange.moveEnd('character', selEnd); \nrange.moveStart('character', selStart); \nrange.select(); \n} \n}\n\nwindow.onload=function(){\nsetSelRange(document.theForm.textbox, 0, 0);\n}\n\nfunction validateFormOnSubmit(theForm) {\nvar reason = \"\";\nreason += validateName(theForm.name);\nreason += validatePhone(theForm.phone);\nreason += validateEmail(theForm.emaile);\n\nif (reason != \"\") {\nalert(\"Some fields need correction:\\n\" + reason);\nreturn false;\n}\n\nsimpleCart.checkout()\n}\n\n\n\nfunction validateEmpty(fld) {\nvar error = \"\";\n\nif (fld.value.length == 0) {\n    fld.style.background = '#3399ff'; \n    error = \"The required field has not been filled in.\\n\"\n} else {\n    fld.style.background = 'White';\n}\nreturn error;  \n}\n\n\n\nfunction trim(s)\n{\nreturn s.replace(\/^\\s+|\\s+$\/, '');\n}\n\nfunction validateName(fld) {\nvar error = \"\";\nvar illegalChars = \/\\W\/; \/\/ allow letters, numbers, and underscores\n\nif (fld.value == \"\") {\n    fld.style.background = '#3399ff'; \n    error = \"Please enter a name.\\n\";\n} else if ((fld.value.length &lt; 2) || (fld.value.length &gt; 30)) {\n    fld.style.background = '#3399ff'; \n    error = \"The nme is too long!\\n\";\n} else {\n    fld.style.background = 'White';\n}\nreturn error;\n}\n\nfunction trim(s)\n{\nreturn s.replace(\/^\\s+|\\s+$\/, '');\n}\n\nfunction validateEmail(fld) {\nvar error=\"\";\nvar tfld = trim(fld.value);                        \/\/ valu\ntrimmed off\nvar emailFilter = \/^[^@]+@[^@.]+\\.[^@]*\\w\\w$\/ ;\nvar illegalChars= \/[\\(\\)\\\\,\\;\\:\\\\\\\"\\[\\]]\/ ;\n\nif (fld.value == \"\") {\n    fld.style.background = '#3399ff';\n    error = \"Please enter an email address.\\n\";\n} else if (!emailFilter.test(tfld)) {              \/\/test email for illegal characters\n    fld.style.background = '#3399ff';\n    error = \"Please enter a valid email address.\\n\";\n} else if (fld.value.match(illegalChars)) {\n    fld.style.background = '#3399ff';\n    error = \"The email address contains illegal characters.\\n\";\n} else {\n    fld.style.background = 'White';\n}\nreturn error;\n} \n\nfunction validatePhone(fld) {\nvar error = \"\";\nvar stripped = fld.value.replace(\/[\\(\\)\\.\\-\\ ]\/g, '');    \n\nif (fld.value == \"\") {\n    error = \"Please enter a phone number.\\n\";\n    fld.style.background = '#3399ff';\n } else if (isNaN(parseInt(stripped))) {\n    error = \"The phone number can only contain numbers.\\n\";\n    fld.style.background = '#3399ff';\n } else if (!(stripped.length == 10)) {\n    error = \"The phone number is the wrong length.     area        code.\\n\";\n    fld.style.background = '#3399ff';\n}\nreturn error;\n}\n<\/code><\/pre>\n<p>I am tring to then run the function simpleCart.checkout() when the form successfully validates: (from the above code)<\/p>\n<pre><code>  if (reason != \"\") {\nalert(\"Some fields need correction:\\n\" + reason);\nreturn false;\n}\n\nsimpleCart.checkout()\n}\n<\/code><\/pre>\n<p>here is the function from <strong>simpleCart.js<\/strong> I am tring to call, (set to emailCheckout):<\/p>\n<pre><code>me.checkout = function() {\n    if( me.quantity === 0 ){\n        error(\"Cart is empty\");\n        return;\n    }\n    switch( me.checkoutTo ){\n        case PayPal:\n            me.paypalCheckout();\n            break;\n        case GoogleCheckout:\n            me.googleCheckout();\n            break;\n        case Email:\n            me.emailCheckout();\n            break;\n        default:\n            me.customCheckout();\n            break;\n    }\n};\n\nme.emailCheckout = function() {    \n\nitemsString = \"\";\nfor( var current in me.items ){ \n    var item = me.items[current];\n    itemsString += item.name + \" \" + item.quantity + \" \" + item.price + \"\\n\";\n}   \n\nvar form = document.createElement(\"form\");\nform.style.display = \"none\";\nform.method = \"POST\";\nform.action = \"js\/sendjs.php\";\nform.acceptCharset = \"utf-8\";\nform.appendChild(me.createHiddenElement(\"wsp_key\", wsp_key));\nform.appendChild(me.createHiddenElement(\"wsp_code\", wsp_code));\nform.appendChild(me.createHiddenElement(\"textbox\", textbox));\nform.appendChild(me.createHiddenElement(\"name\",name));\nform.appendChild(me.createHiddenElement(\"phone\",phone));\nform.appendChild(me.createHiddenElement(\"emaile\",emaile));\nform.appendChild(me.createHiddenElement(\"jcitems\", itemsString));\nform.appendChild(me.createHiddenElement(\"jctotal\", me.total));\ndocument.body.appendChild(form);\nform.submit();\ndocument.body.removeChild(form);\n}\n<\/code><\/pre>\n<p>It recieves the cart info, inputs and captcha key and code from the form and actions sendjs.php to mail it to me:<\/p>\n<p>(from the code above)<\/p>\n<pre><code>form.action = \"js\/sendjs.php\";\n<\/code><\/pre>\n<p>If the captcha code is correct it will mail it to me and redirect to &#8220;from-accepted.php&#8221; page, if not it will redirect to a &#8220;form-rejected.php&#8221; page (sendjs.php):<\/p>\n<pre><code>\n<\/code><\/pre>\n<p><strong>The problem is that after validation is doesn&#8217;t action sendjs.php and just reloads the contact page. Debugger is showing no error and I have tested simpleCart.checkout by other means and it should work. Sorry for the length of this post but I am stumped and am losing business (and a lot of sleep trying to get it to work) not having this form functioning.<\/strong><\/p>\n<p>here is a link to the page:<\/p>\n<p>http:\/\/www.diysoakwells.com.au\/cart.php<\/p>\n<p>Does anyone have any suggestions? I have to pop out now for an hour but I will be monitoring this post and when I return, working on the problem for at least the next four or five hours or until its fixed. Thanks in advance.<\/p>\n<p>Jamie<\/p>\n","protected":false},"excerpt":{"rendered":"<p>this is an expanded version of a question I asked last night, but with much more detail. All my php files and js file are in a folder called js one level down from my html pages. I have a contact form that mails the content of my shopping cart and form inputs to my [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3271","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3271","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3271"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3271\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}