【发布时间】:2016-01-04 08:26:16
【问题描述】:
我需要使用表单数据绑定将数据绑定到相关字段,但数据根本没有显示在字段上。我不知道究竟是什么问题阻止了数据出现。
控制器:
public function edit($id){
$datum = RatingDatum::findorfail(1);
return view('rating.index',compact('datum'));
}
查看:
<div class="plan bg-plan">
{!! Form::model($datums,['method' => 'PATCH','action'=>'RatingDataController@update'],$datums->id]) !!}
<div class="radio">
<label>
{!! Form::radio('customize_question_id')!!}{{$datums->value}}
</label>
</div>
<div class="form-group">
{!! Form::label('comment','Comment :') !!}
{!! Form::textarea('comment' ,null,['class'=>'form-control', 'rows' => 4]) !!}
{!! Form::label('reference','Reference:') !!}
{!! Form::textarea('reference',null,['class'=>'form-control', 'rows' => 1]) !!}
</div>
{!! Form::submit('Submit Data', ['class' => 'btn btn-success submit']) !!}
{!! Form::close() !!}
</div>
dd($datum);
#attributes: array:15 [▼
"id" => 1
"organisation_id" => 8
"sector_id" => 1
"country_id" => 1
"dimension_id" => 12
"question_angle_id" => 1
"customize_criteria_id" => 33
"customize_question_id" => 7591
"question_weight" => 20
"actual_score" => 75
"value" => "The company has made a formal commitment to promoting voluntary community initiatives and has set up quantitative targets in this regard."
"comment" => ""
"reference" => ""
"created_at" => "2015-12-21 11:28:38"
"updated_at" => "2015-12-21 12:22:25"
]
【问题讨论】:
-
如您所见,
reference和comment为空,因此文本框将为空 -
是数据绑定,即使字段为空,数据也会自动添加到相关字段中
-
我的意思是说数据库中的值是空的。检查您的
dd数据 -
单选按钮也有问题:(
-
{!! Form::radio('customize_question_id', $datums->customize_question_id, $datums->customize_question_id != null ? 'true' : 'false')!!}
标签: php forms data-binding laravel-5