I am trying to get user answers on a form. And after submitting the form, I can reach to all form values.
But some how, text field values are not recorded. They are recorded as NULL.
I tried with input array like
<input type=”text” name=”answer_1[]”>
or like
<input type=”text” name=”answer_1_1″>
result is the same.
At the beginning it was recording the values, but then nothing. Other form values are recording
enter image description here
I added $fillable and $guarded keys to model
protected $fillable = [‘cevap’];
protected $guarded = [];
Form part
`<div class="col-12 answer">
<div class="row">
<div class="col-10 col-md-10">
<input type="text" class="form-control form-control-sm" name="answer_6_1" value=""/>
</div>
<div class="col-2 col-md-2 ">
<button type="button" class="btn btn-xs btn-danger" onclick="removeRow(this)">
<i class="fa fa-trash"></i></button>
</div>
</div>
</div>
<div class="col-12 answer">
<div class="row">
<div class="col-10 col-md-10">
<input type="text" class="form-control form-control-sm" name="answer_6_2" value=""/>
</div>
<div class="col-2 col-md-2 ">
<button type="button" class="btn btn-xs btn-danger" onclick="removeRow(this)">
<i class="fa fa-trash"></i> </button>
</div>
</div>
</div>`
Controller part
`$request->validate([
'form_id' => 'required|exists:AppModelsBrainStormForm,id'
]);
$form_id = $request->form_id;
$user_id=auth()->user()->id;
$company_id=auth()->user()->company_id;
for($j=1;$j<=6;$j++){
$max=$request->input('category_count_'.$j);
for($i=1;$i<$max;$i++){
$answer_1=$request->input('answer_'.$j.'_'.$i);
$ba = new BrainAnswer();
$ba->form_id = $form_id;
$ba->user_id = $user_id;
$ba->company_id = $company_id;
//$brainstorm_answer->answer =$answer_1;
$ba->cevap =$answer_1; //this part is to hold value
$ba->cevap2 =$answer_1;
$ba->category_id = $j;
$ba->save();
// ddd($brainstorm_answer);
}
}`
Form data (from laravel Log)
array (
'_token' => 'g1JTcYP601ATpW7UYqsbhPGpkKiJlBKTVPjG7y6X',
'form_id' => '6',
'p7' => 'dsfsdfasd fsad fsadf',
'p8' => 'sdfasdf asfd',
'answer_1_1' => 'fsdfsadfadf',
'answer_1_2' => 'sdfsdf s',
'category_count_1' => '3',
'answer_2_1' => 'erwer',
'category_count_2' => '3',
'answer_2_2' => 'werwf',
'answer_3_1' => 'sdfwer',
'answer_3_2' => 'sdfsdf',
'category_count_3' => '3',
'answer_4_1' => 'asdfsf',
'answer_4_2' => 'sdfser',
'category_count_4' => '3',
'answer_5_1' => 'werwqer',
'answer_5_2' => 'wqrwer',
'category_count_5' => '3',
'answer_6_1' => 'werwer',
'answer_6_2' => 'qwerwer',
'category_count_6' => '3',
)
Bekir Güler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.