mardi 29 décembre 2015

Laravel: How to bind form data

Scenario:

I have a form for each subject and each subject have three or four questions and the user have to answer those question then save the data on the database

The problem:

How to bind the data with the form so the form refilled with the data that inputted before by the user. I have tried a lot and search a lot to find a solution but I didn't find anything useful.

Code: View :

   <div class="row">
                {!! Form::model(['method' => 'PATCH','action'=>['RatingDataController@saveData'],$organisation->id,$organisation->sector->id]) !!}
           <div class=" col-md-9">
                            <h3> {{$subject_name->subject}}</h3>
                            @foreach($question as $index=>$question)
                                <div class="plan bg-plan">
                                    <h5>{{$question->question}}</h5>
                                    <hr>
                                    <!-- create sector form -->
                                    @foreach($answers as $answer)
                                            <div class="radio">
                                                <label> 
                             {!! Form::radio('row['.$index.'][answer_id]', $answer->id,true)!!}                                                        
                                                  {{$answer->answer}}
                                                </label>

                                            </div>
                                    @endforeach
                                    <div class="form-group">
                                        {!! Form::label('comment','Comment :') !!}
                                        {!! Form::textarea('row['.$index.'][comment]' ,null,['class'=>'form-control', 'rows' => 4]) !!}
                                    </div>                             
                                </div>
                            @endforeach
                        </div>
                        {!! Form::submit('Submit Data', ['class' => 'btn btn-success submit right']) !!}

                        {!! Form::close() !!}
                    </div>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire