Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get selected radio button value in Laravel

Hi all how to get selected radio button value. I want to store values on my table where selected radio button.

My Controller code passing to View $result

        $result =     DB::table('table')
                                ->where('name', $name)
                                ->where('code', $code)
                                ->get();

        return  View::make('home.search_result')            
                       ->with('result', $result);

In my view code I had radio button.

{{ Form::open(array('action' => 'BookingController@postValue',  'class'=>'well', 'method' => 'GET')) }}         
<table id="search" class="table table-striped table-hover">
    <thead>
        <tr>
            <th></th>
            <th>Name</th>
            <th>Code</th>                                                                                                              
        </tr>
    </thead>
    <tbody> 
        @foreach($result as $result)                                    
            <tr class="success">    
                <td>{{ Form::radio('result') }}
                <td>{{ $result->name}}</td>                 
                <td>{{ $result->code}}</td>                 
            </tr>                       
        @endforeach                           
    </tfoot>
</table>           

{{ Form::submit('Add', array('class' => 'btn btn-info')) }}         
{{ Form::close() }}         

So I try to pass chechked radio button value to my postValue function when I click Add button.

like image 723
JaN Avatar asked Apr 27 '14 08:04

JaN


People also ask

How to get selected radio button value php?

Get Selected Value of a Radio Button in PHPUse $_POST[] to get the value of the selected radio button. If the value is not chosen, we are showing a message to the user to choose the value from the group of radio buttons.

How to get multiple radio button value in php using POST?

To display radio buttons value. <? php if (isset($_POST['submit'])) { if(isset($_POST['radio'])) { echo "<span>You have selected :<b> ". $_POST['radio']."</b></span>"; } else{ echo "<span>Please choose any radio button.

How do you check whether a Radiobutton is checked or not in php?

When a form has a radio button with a name, you can get the checked radio button by accessing either $_POST or $_GET array, depending on the request method. The filer_has_var() returns true if it finds the radio button name in the INPUT_POST .


2 Answers

You need to give the radio button a value. All you've given it is a name.

<td>{{ Form::radio('result', $result->code) }}

Then in your controller that processes the form you can grab the value.

$result = Input::get('result');
like image 84
Jason Lewis Avatar answered Sep 18 '22 06:09

Jason Lewis


You need to give a name to the radio button.

Normal HTML : <input name="sex" type="radio" value="male">

Laravel : {{ Form::radio('sex', 'male') }}

Form::radio('name','value');

Laravel gets parameter for name and value.

like image 28
Disapamok Avatar answered Sep 19 '22 06:09

Disapamok