This is the code which sends data to the database. It works correctly when I filled form field and click the 'Add Record' button. It inserts the data successfully in the database.
However the main problem is that if the form field is empty and then I click the button, it sends empty data to the database.
function addRecord() {
var formData = new FormData($("#form1")[0]); //It automatically collects all fields from form
$.ajax({
url: "ajax/EditDeleteLecture.php",
type: "post",
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
success: function(output) {
alertify.set('notifier', 'delay', 3);
alertify.set('notifier', 'position', 'top-right');
alertify.success('Data Inserted Successfully');
readRecords();
$('#form1').trigger("reset");
}
});
}