bashirudeen ahmad
bashirudeen ahmad

Reputation: 213

Laravel radio button name not showing in input request when radio button nothing selected

{!!Form::text('first_name','')!!}
{!!Form::text('last_name','')!!}

{!!Form::radio('status','1')!!}
{!!Form::radio('status','2')!!}

Above radio button nothing selected, when submit the input to controller,

public function store(Request $request)
{
    $inputArray = $request->all();
    echo "<pre>";
    print_R($inputArray);
    exit;
}

Below are the response for the input array:

Array
(
    [_token] => 0yavNy0XLB7YM4xSnKFR7LZqfwTqkybBum3tnkJQ
    [first_name] => 
    [last_name] => 
)

Why the radio input name(status) does not shows in request. I want the below response.

Array
(
    [_token] => 0yavNy0XLB7YM4xSnKFR7LZqfwTqkybBum3tnkJQ
    [first_name] => 
    [last_name] => 
    [status] =>
)

Please help. Thanks in Advance.

Upvotes: 1

Views: 978

Answers (1)

Md Mahfuzur Rahman
Md Mahfuzur Rahman

Reputation: 2359

Put a hidden field for status like this.

{!!Form::text('first_name','')!!}
{!!Form::text('last_name','')!!}

{!!Form::hidden('status','0')!!}

{!!Form::radio('status','1')!!}
{!!Form::radio('status','2')!!}

If status is not selected, value will be zero

Upvotes: 2

Related Questions