I am trying to submit the form after filling out the form fields but it is not getting submitted and also not getting any kind of errors on console as well as network.
My create.blade for form:
<form method="POST" class="create_form" id="form" action="{{ route('details.store') }}" enctype="multipart/form-data">
@csrf
<tr>
<td>Name</td> <td><input type="text" name="name" ></td></tr>
<tr><td>Age</td> <td><input type="text" name="age" ></td></tr>
<tr><td>Address</td> <td><input type="text" name="address" ></td></tr>
<tr><td>Contact</td> <td><input type="text" name="contact" ></td></tr>
<tr><td>Email</td> <td><input type="text" name="email"></td></tr>
<tr><td>Gender:</td>
<td><input type="radio" name="gender" value="Male" checked>Male</td></tr>
<tr><td></td><td><input type="radio" name="gender" value="Female">Female</td></tr>
<tr><td>Qualification </td><td>
<select name="qualification">
<option value="SSC">SSC</option>
<option value="HSC">HSC</option>
<option value="UG">UG</option>
<option value="PG">PG</option></select></td></tr>
<tr><td>Hobbies:</td>
<td><input type="checkbox" name="hobbies[]" value="Trading">Trading</td></tr>
<td></td><td><input type="checkbox" name="hobbies[]" value="Games">Games</td></tr>
<td></td><td><input type="checkbox" name="hobbies[]" value="Music">Music</td></tr>
<td></td><td><input type="checkbox" name="hobbies[]" value="Swimming">Swimming</td></tr>
<tr><td>Profile Picture</td> <td><input type="file" name="profilepic"></td></tr>
<tr><td>Signature</td> <td><input type="file" name="signature"></td></tr>
<tr><td><button type="button" class="save_create">Save</button></td>
<td><button type="button" class="back">Back</button></td></tr>
</form>
My ajax jquery code for submit button:
$(document).on('submit','.create_form',function(event)
{
event.preventDefault();
var data = $(this).serialize();
$.ajax({
url: "{{ route('details.store') }}",
data: data,
type: "POST",
dataType: "json",
success: function(response)
{
window.location.href = ("{{ route('details.index') }}");
},
error: function(error)
{
console.log("Errors :",error);
}
});
});
I also tried to get the result and error in the console but still getting none of them.
Also I used
<input type="submit" class=save_create>
but still not getting submitted.
2
Answers
you need to handle like this Instead of AJAX
if you want ajax then use like this
You can use in html form id and this form 2 file add so you can use form_data.append like that