我有一个表单,要求用户制作10个游戏选择,然后根据信心对选择进行排序。我正在使用jQuery的可排序函数,然后在每次更新订单时使用序列化字符串填充隐藏的表单元素(order-array)。我的问题是如何在提交后在我的控制器中处理这一系列的序列化数据,这样我就可以将它(加上实际的游戏选择)存储到我的数据库中。
{{ Form::open() }}
<h1>Games for Week {{ $weeknum }} </h1>
<h3>Visitors @ Hometeam</h3>
<input type="hidden" name="order-array" id="order-array" value="">
<ul id="gamelist">
<?php $count = 1; ?>
@foreach($games as $game)
<li class="game-rank" id="c_{{ $count }}">
<input type="radio" name="{{ "pick_".$game->id }}" value="{{ $game->visitor }}">
{{ $game->visitor }} @
<input type="radio" name="{{ "pick_".$game->id }}" value="{{ $game->hometeam }}">
{{ $game->hometeam }}
<input type="hidden" name="{{ "game_".$count }}" value="{{ $game->id }}">
</li>
<?php $count++; ?>
@endforeach
</ul>
@if(Auth::check())
{{ Form::hidden('player', $player) }}
{{ Form::submit('Submit Picks', array('class' => 'link-button')) }}
@endif
{{ Form::close() }}
"c[]=1&c[]=3&c[]=9&c[]=4&c[]=5&c[]=6&c[]=2&c[]=7&c[]=8&c[]=10"
public function post_new()
{
$confidence = Input::get('order-array');
for ($i=1;$i<=10;$i++) {
$array_index = $i-1;
$pick = new Pick;
$pick->user_id = Input::get('player');
$pick->game_id = Input::get("game_$i"); // game number
$pick->pick = Input::get("pick_$i"); // teamname
$pick->confidence = $confidence[$array_index];
$pick->save();
}
return Redirect::to ('users');
}
除了置信度数据外,一切都有效。我需要对控制器进行哪些调整? 谢谢!