I am trying to validate and submit a form from a site made with Laravel 5.2 The problem comes, when i try to submit the form without filling all required fields. The StoreRequest checks which fields are required and returns me the errors like that:
{"name":["The name field is required."],"email":["The email field is required."],"subject":["The subject field is required."],"content":["The content field is required."]}
Here is how i submit the form and how i want to display the errors of the validation:
$("#contact_form").submit(function() {
$.post("", {"_token": "" },
function(data) {
if(data) {
var items = [];
$.each( data, function( key, val ) {
items.push( "<li id='" + key + "'>" + val + "</li>" );
});
$( "<ul/>", {
"class": "my-new-list",
html: items.join( "" )
}).appendTo("#errors");
}
});
return false;
});
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire