Home » Php » php – My laravel collective form is not submitting when I click submit

php – My laravel collective form is not submitting when I click submit

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have a form in my blade template when I click submit button nothing is happing it is not going to my controller.
this is the form

{{Form::open(['action' => ['[email protected]'], 'method' => 'POST']) }} 

{!! Form::select('city_add', array("CAM" => "CAM","KL" => "KL","IPOH" => "IPOH"), 'S',['style'=>'   

 }'],['class' => 'form-control','placeholder'=>'hotel_name']); !!}
{{Form::text('city_add',"CAM") }}
  {{Form::submit('Submit',['class'=>'btn btn-danger'])}}
  {!! Form::close() !!}

this is my route

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

My route controller

How to&Answers:

Your form select element like below:
You should not use same name for the select tag and input tag.

{{Form::open(['action' => ['[email protected]'], 'method' => 'POST']) }} 

    {!! Form::select('city_option', array("CAM" => "CAM","KL" => "KL","IPOH" => "IPOH"),['class' => 'form-control','placeholder'=>'hotel_name']); !!}
    {{Form::text('city_add',"CAM") }}
    {{Form::submit('Submit',['class'=>'btn btn-danger'])}}
{!! Form::close() !!}

And In controller( for the test )

public function addcity(Request $request )
{
    echo '<pre>';
    print_r($request->all());
    exit(); 
}

if you would like to add style in form element use below code:

{{Form::open(['action' => ['[email protected]'], 'method' => 'POST']) }} 

    {!! Form::select('city_option', array("CAM" => "CAM","KL" => "KL","IPOH" => "IPOH"),'S',['style'=>'color:red'],['class' => 'form-control','placeholder'=>'hotel_name']); !!}
    {{Form::text('city_add',"CAM") }}
    {{Form::submit('Submit',['class'=>'btn btn-danger'])}}
{!! Form::close() !!}