2017-04-05 13 views
1

私はblade.phpにフォームを作成します。ここで複数のチェックボックスを選択できます。選択した入力値を配列のコントローラに渡したいと思います。しかし、失敗しました。データを送信できません。 ここにはコードが表示されています。選択された入力の値は1,2などです。私は必要だ配列をLaravelのビューからコントローラに渡す方法は?

{"_token":"TQIUxVz0LjzM84Z7TaUPk3Y7BLZPjmXUyhXhlQfp","selected": 
    ["1","2"]} 

- 私は私が見つけるコントローラに戻り$入力を記述する場合

<form method="post" action="{{action('[email protected]')}}" class="form"> 

<input type="hidden" name="_token" value="{{ csrf_token() }}"> 

@foreach($candidate_list[$post_list->id] as $candidate_list[$post_list->id]) 

<li> 
    <input type="checkbox" name= "selected[]" value= {{ 
$candidate_list[$post_list->id]->id }}> 
    <label> 
    <!-- some code here --> 
    </label> 
</li> 

@endforeach 
<button type="submit" id="login-button">Submit</button> 
</form> 

はここ

Route::post('/votesubmit','[email protected]'); 

route-です。私は選択された価値を得る方法を知らない。特定のルートエラーが発生すると例外が発生します。 "Undefined variable:selected"と表示されます。ここ は $選択= $入力[ '選択'] を使用するか、 AJAXを使用して、それを渡すのどちらか、私のコントローラのコード -

class votesubmitController extends Controller 
{ 
public function votesubmit() 
{ 
    $input = Input::all(); 
// return $input;  
    foreach ($selected as $selected) { 
    echo $selected; 
    } 
} 
} 
+1

'$ selected = 'selected'];'これをコントローラに追加します。 – linktoahref

+0

ありがとう、それは... –

+0

@linktoahref。答えに入れてください。そしてAlimurは、この問題を解決して表示できるように受け入れる –

答えて

0

です。

2
// You can try this 
class votesubmitController extends Controller 
{ 
public function votesubmit() 
{ 
    //$input = Input::all(); 
    //$selected = $input['selected']; 
    $selected = Input::get('selected'); 
    foreach ($selected as $selected) 
    { 
    echo $selected; 
    } 
} 
} 
関連する問題