I have a form comment section whereby a user can reply to a comment. Each comment has a form with a reply box. Am getting the comments from the database and running the following loop.
@foreach($responses as $response)
<li>{{$response->answer}}</li>
<form action="{{action('DiscussionController@postAnswerQuestion', [$entry_year, $grade_id, $subject_id, $question_id])}}" method="post" id="form1">
<input type="text" name="reply" value="" placeholder="Reply">
<input type="hidden" name="response_id" value="{{$response->id}}">
<input type="submit" name="" value="reply">
</form>
@endforeach
When I submit the php form using normal PHP it submits just fine but when using jquery ajax and the following code.
var formData = {
'answer' : $('input[name=answer]').val(),
'reply' : $('input[name=reply]').val(),
'response_id' : $('input[name=response_id]').val(),
};
It returns the value of the first input only after some googling I found that I should use serialize and so instead of the above jquery code I used the following
var formData = $('#form1').serialize();
But now the values arent being captured and the values are coming to php as null. How should I solve the above problem?
Thanks a lot guys!
id="form1"in a loop ->@foreach($responses as $response), so instead of uniqueids, you have multiple sameids