James Russel
James Russel

Reputation: 17

Request data from textbox returns null

Good day, i have a little problem, I'm new in laravel and i don't know what is causing this problem

i have a form enter image description here

the code for the form is

<form action="/search">
    {{ csrf_field() }}
    <div class="row">
          <div class="col-lg-4 col-md-4 col-sm-12">
                <label>Search doctors, conditions or procedures</label>
                <input type="text" name="search_speciality" class="search_filter_textbox" placeholder="Speciality">
          </div>
          <div class="col-lg-4 col-md-4 col-sm-12">
                <label>For treatment near</label>
                <input type="text" name="search_speciality" class="search_filter_textbox" placeholder="City/ZIP Code">
           </div>
           <div class="col-lg-4 col-md-4 col-sm-12 search_filter_btn_wrapper">
                <button type="submit" class="btn btn-info search_filter_btn">Search</button>
           </div>
    </div>

Here is my route

Route::get('/search', 'doctorController@search');

Here is my Controller

 public function search(Request $request){

    $textbox1 = $request->get('search_speciality');

    dd($textbox1);
}

i wanted to check if the request is working, but when i did this, the output was enter image description here

i displays null even though i inputted a data on the text which is "James" for this example

Upvotes: 0

Views: 37

Answers (1)

Rehmat
Rehmat

Reputation: 5071

You have two input fields with the same name search_speciality. Check through your code carefully. You need to change your code so it looks something like:

<form action="/search">
    {{ csrf_field() }}
    <div class="row">
          <div class="col-lg-4 col-md-4 col-sm-12">
                <label>Search doctors, conditions or procedures</label>
                <input type="text" name="search_speciality" class="search_filter_textbox" placeholder="Speciality">
          </div>
          <div class="col-lg-4 col-md-4 col-sm-12">
                <label>For treatment near</label>
                <input type="text" name="search_city" class="search_filter_textbox" placeholder="City/ZIP Code">
           </div>
           <div class="col-lg-4 col-md-4 col-sm-12 search_filter_btn_wrapper">
                <button type="submit" class="btn btn-info search_filter_btn">Search</button>
           </div>
    </div>
</form>

Upvotes: 3

Related Questions