I am currently doing so and every time I submit the form the alert returns error even with the fields filled in correctly
$('.form-ajax').on('submit', function(e) {
e.preventDefault();
var form = $('#formnews');
$.ajax({
method: 'POST',
url: form.attr('action'),
async: true,
data: form.serialize(),
cache: false,
success: function(result) {
if (result.success) {
swal('Bom trabalho!', 'Sua inscrição foi efetuada com sucesso!', 'success');
$('#formnews').val('');
} else {
swal('Alguma coisa errada', result.message, 'warning');
}
},
error: function(data) {
swal('Erro!', 'Ocorreu um erro', 'error');
}
})
});
<form action="{{ route('newsletter.post.ajax') }}" method="POST" id="formnews">
{{ csrf_field() }}
<div class="field has-addons">
<div class="control is-expanded has-icons-left has-icons-right">
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<p class="control is-expanded has-icons-left has-icons-right">
<input id="email_newsletter" type="email_newsletter" class="input" name="email_newsletter" value="{{ old('email_newsletter') }}" placeholder="Seu melhor email" required>
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
<span class="icon is-small is-left">
<i class="fa fa-envelope"></i>
</span>
<span class="icon is-small is-right">
<i class="fa fa-check"></i>
</span>
</p>
</div>
</div>
<div class="control">
<button type="submit" class="button is-warning">
Cadastrar
</button>
</div>
</div>
</form>