I have a form that asks the user to make 10 game picks and then sort the picks based on confidence. I'm using jQuery's sortable function and then populating a hidden form element (order-array) with a serialized string on each update to the order. My problem is how to deal with this array of serialized data in my controller after submission so I can store it (plus the actual game picks) into my database.
My Form View
{{ 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() }}
The serialized confidence data being passed to the controller
"c[]=1&c[]=3&c[]=9&c[]=4&c[]=5&c[]=6&c[]=2&c[]=7&c[]=8&c[]=10"
My controller function
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');
}
Everything works except for the confidence data. What adjustments do I need to make to my controller?
Thanks!!