Hi I am trying to execute a php function inside a javascript function. This javascript function is a form validation method which is called on through onclick method. This function validates the form fields and inserts the data into the mysql database.
I am calling this php function only when the form values are validated. The problem is that even when the form entries are not validated, that is, even when i enter wrong data the function is being called.
However, if dont call the function here inside the script and i enter the php inside the body the validation works.
jobs.php:
<script type="text/javascript">
function validate(){
var name= document.forms["Jform"]["name"];
var email= document.forms["Jform"]["email"];
var Experience= document.forms["Jform"]["experience"];
var letters=/^[A-Za-z]+$/;
var boolean=true;
var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
if(name.value == ""){
alert("Please enter your name");
name.focus();
boolean=false;
return false;
}
if((!email.value.match(mailformat)) || email.value==""){
window.alert("Please enter proper email");
email.focus();
boolean=false;
return false;
}
if(Experience.value==""){
window.alert("Please enter valid characters");
email.focus();
boolean=false;
return false;
}
if(boolean){
<?php
insertfunc();
?>
}
}
</script>
This is my code.
To rephrase, i want the php function to execute only when the form values are validated.
Could someone please help