I am going to submit a form after validating the form as follows, here first I use a ajax post and check whether duplicate values are exist if exist ajax will return html code else return 'false'. Dialog box should popup if ajax return is a 'html code'. If ajax return is false form_validate() should return true. Which means no duplicates, form will submit for insert data. If user clicked Ok on the Dialog box, form_validate() should return true which means there are duplicates, form will submit for update data. If user clicked Cancel form_validate() should return false which means form will not submit. I am working on this hours but couldn't figure it out. Plz Help.
function form_validate(){
$.post('index.php',{ .....
},function(result){
if(result!='false'){
$('<div></div>')
.html(result+'<br/>Click OK to confirm. Click Cancel to stop this action.')
.dialog({
buttons : {
"OK": function() {
$(this).dialog("close");
return true;
}, "Cancel": function() {
$(this).dialog("close");
return false;
}
}
}
});
}
<form>
Tag
<form action="index.php" method="post" name="adminForm" onsubmit="return validate_form();" >