I need to validate the form, the ajax should only work if the form validates

124 views Asked by At

I'm trying to validate the form. Its validating perfectly but the form is not submitting. In the console it says isValid() is not a function

I tried to give a condition that form validates

$('#saveStudent').parsley();
var addvalidation = new JustValidate('#saveStudent');

addvalidation.addField('#poster', [{
  rule: 'files',
  value: {
    files: {
      extensions: ['jpeg', 'png', 'jpg'],
      // maxSize: 25000,
      // minSize: 1000,
      types: ['image/jpeg', 'image/png', 'image/jpg'],
      // names: ['file1.jpeg', 'file2.png'],
    },
  },
  errorMessage: 'Only jpeg, jpg, png formats are supported.',
}, ]);
$(document).on('submit', '#saveStudent', function (e) {
  e.preventDefault();
  var formData = new FormData(this);
  formData.append("save_student", true);
  
  if ($(this).parsley().isValid() && addvalidation.isValid()) {
    $.ajax({
      type: "POST",
      url: "save.php",
      data: formData,
      processData: false,
      contentType: false,
      success: function (response) {
        $('#addMovie').show();
        $('#studentAddModal').modal('hide');
        $('#saveStudent')[0].`your text`reset();
        $('#myTable').load(location.href + " #myTable");
      }
    });
  }
});
0

There are 0 answers