【发布时间】:2013-11-29 01:31:50
【问题描述】:
在我的编辑表单的一部分中,我有复选框。我可以很好地提交表单,这些值作为逗号分隔值存储在数据库中。所以苹果,微软等。哪个工作正常但是当我回到编辑表单时,复选框没有被选中。如果满足以下条件,我尝试回显检查:
<input name="software[]" type="checkbox" value="Ortho trac" <?php if(isset($_POST['software'])) echo "checked"; ?>> Ortho trac
但是上面的代码不起作用。我不知道如何在 laravel 中做到这一点。 当我尝试更新值时,数据库中的先前值消失了
观点
<div class="form-group mtop-20">
<label for="temp_software_experience">Software Experience:</label><br>
<label class="checkbox-inline">
<input name="software[]" type="checkbox" class="input-sm" value="Practiceworks"> Practiceworks
</label>
<label class="checkbox-inline">
<input name="software[]" type="checkbox" value="Softdent"> Softdent
</label>
<label class="checkbox-inline">
<input name="software[]" type="checkbox" value="Ortho trac" <?php if (isset($_POST['software'])) echo "checked"; ?>> Ortho trac
</label>
<label class="checkbox-inline">
<input name="software[]" type="checkbox" value="Dentrix"> Dentrix
</label>
<label class="checkbox-inline">
<input name="software[]" type="checkbox" value="Easy Dental"> Easy Dental
</label>
<label class="checkbox-inline">
<input name="software[]" type="checkbox" value="Practiceworks"> Eaglesoft
</label>
<label class="checkbox-inline">
<input type="checkbox" id="temp_software_experience" value="Other"> Other
</label>
</div><!-- end .form-group -->
控制者
public function update($id)
{
// validate
// read more on validation at http://laravel.com/docs/validation
$rules = array(
'firstname' => 'required|min:3|alpha',
'lastname' => 'required|min:3|alpha',
'zipcode' => 'required|min:5|numeric',
'temp_experience' => 'required|min:1|max:50|numeric',
'temp_travel' => 'required|numeric',
'temp_hourly_rate' => 'required|numeric|min:10',
);
$validator = Validator::make(Input::all(), $rules);
// process the login
if ($validator->fails()) {
return Redirect::to('user/profile/' . $id . '/edit')
->withErrors($validator)
->withInput();
} else {
$software_checked = Input::get('software');
if(is_array($software_checked))
{
$implade_software = implode(',', $software_checked);
}
// store
$user = User::find($id);
$user->firstname = Input::get('firstname');
$user->lastname = Input::get('lastname');
$user->zipcode = Input::get('zipcode');
$user->temp_experience = Input::get('temp_experience');
$user->temp_travel = Input::get('temp_travel');
$user->temp_hourly_rate = Input::get('temp_hourly_rate');
$user->temp_software_experience = $implade_software;
$user->save();
// redirect
Session::flash('message', 'Successfully updated profile!!');
return Redirect::to('user/profile/'.$id.'');
}
}
【问题讨论】: