php and javascript form validation issue -


i have created form using bootstrap , using javascript form validation , php script grab post data , display it

the basic structure following , have made minimal address specific issue. issue having script check form validation works in <script> tags @ end of body, instead of preventing page being submitted should still processes next page form's contents being made through php post action when form indeed not filled out correctly.

why this? should form validation still not stop page moving on post data since validation returning false if form has not been submitted correctly. form validation alerts pop correctly , i;m getting no console errors after checking, or need perform additional check process post data if form valid?

<html>    other tags.....    <body>       <form name = "orderform" action = "process_order.php" onsubmit = "orderbutton" method = "post">           bunch of content, divs, checkboxes, etc       </form>    </body>    <script>              function checkform() {                     var name = document.getelementbyid("name");                     var fries = document.forms.orderform.fryradio;                     var fryyes = fries[0].checked                     var fryno = fries[1].checked                      var bool = true;                      if ((name.value == "" || name.value == "name") || (!(document.getelementbyid("sandwichradio").checked || document.getelementbyid("wrapradio").checked)))  {                          bool = false;                     }                      else if (!(fryyes || fryno)) {                         bool = false;                     }                      if (!(bool)) {                         alert("please fill out of required fields.");                         return false;                     }                     else {                         alert("your order being submitted");                         console.log("submitted")                     }              };      </script> </html> 

you should call function on submit , dont know doing current onsubmit='...'

so use following, call function when submit form.

  <form name = "orderform" action = "process_order.php" onsubmit = "return checkform()" method = "post">       bunch of content, divs, checkboxes, etc   </form> 

for demo : check fiddle


Comments