I created a form demo.php with simple validations(untouch,dirty,valid/invalid) like on touch input change color to yellow ,on valid change color to green.If all fields are valid then submit button is active.
everything works fine.
On submit it go abc.js file then call ajax process which goes to pusttoDb.php and then the output is carried then display the result in the demo.php.
The following image shows my form.
if all the fields are valid then shows the submit button.
After submit it goes to js file which as following code:
$(document).ready(function(){
alert('form js page');
$( "#myForm" ).on( "submit", function( event ) {
event.preventDefault(); //this will prevent the form from submitting
// var form_data = $("#myForm").serialize();
var data=$("#myForm :input").serializeArray();
$.ajax({
url: "pushtodb.php",
method: "POST",
data: data,
success: function (info) {
$("#result").html(info);
$('#myForm')[0].reset(); // to reset the data
/* $('#myForm').unbind("submit");
this.$('#myForm').form.markAsPristine();
this.$('#myForm').form.markAsUntouched();
this.$('#myForm').form.updateValueAndValidity();*/
}
});
});
});
From the pushtoDb.php file it carries success message but form doesn't reset with all validation and directly showing valid submit button as The below image :
if we observe the above image only data is reset but form is showing as valid and submit input is also valid.
how to reset whole form instead of only data/values?
thanks in advance.