0

Grettings.

I'm trying to call an index view from itself, to look for a person and displaying results to the left.

But when I call the view and send data It always get null, could you please give me a clue. I've even called the store function and request is always null.

It should be a modal window to get the request object? What should I do If I wanted to show the windows as I'm doing it?

My routes

    Route::get('registroaccesos/destinationSearchGet/', 'RegistroAccesosController@destinationSearchGet')->name('registroaccesos.destinationSearchGet');
    Route::post('registroaccesos/destinationSearchPost/', 'RegistroAccesosController@destinationSearchPost')->name('registroaccesos.destinationSearchPost');

The controller

public function destinationSearchGet(){
    $headData = array('pageTitle' => 'Admin Home - View all destinations');
return view('registroaccesos.index', $headData);
}


public function destinationSearchPost(Request $request){
    $headData = array('pageTitle' => 'Admin Home - Search results');
    $formData = $request->input('strPatron');

dd($formData);


//    $data = ParentRegionList::destinationSearch($formData);
    return view('registroaccesos.index', $headData);//->with(compact('data'))
}

The view

enter image description here

Part of the code of the view

        <h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
          <span>Acciones</span>
          <a class="d-flex align-items-center text-muted" href="#">
            <span data-feather="plus-circle"></span>
          </a>
        </h6>

              <div class="form-group">
                <label for="strSearch" class="col-form-label">Patrón de búsqueda</label>
                <select name="strSearch" class="form-control">
                  <option value="1"  selected> Código del usuario</option>
                  <option value="2"  > Nombre del usuario</option>
                  </select> 
              </div>

                      <div class="form-group">
                        <input  placeholder="Patrón de búsqueda"
                                id="strPatron"
                                required
                                name="strPatron"
                                spellcheck="false" 
                                class="form-control"
                                value="Valor"
                                />
                      </div>


              <button class="btn btn-sm btn-outline-secondary"

              onclick="
                    event.preventDefault();
                    document.getElementById('search-form').submit();
              "


              >Buscar</button>
                <form id="search-form" action="{{ route('registroaccesos.store','el resultado'  ) }}" method="POST" style="display: none;">
                 <!--   <input type="hidden" name="_method" value="delete">-->
                    {{ csrf_field() }}
                </form>

The result

enter image description here

Christian Gallarmin
  • 660
  • 4
  • 15
  • 34
Arthur
  • 97
  • 1
  • 10

1 Answers1

0

Well your <input> with name="strPatron" is not in your <form> so it will not get submitted when you submit the form. You need to have all the input elements inside the form or they won't get sent with the POST request.

The way you've got it right now only the CSRF field in your form is getting submitted. You can check this by doing a dd($request->all()) in your controller.

Peter
  • 1,615
  • 1
  • 9
  • 17
  • As you can see I want to put the results to the right, outside of the form. Actually I'm not calling the same function from a form but from a button on the page... As a matter of fact I don't really understand the difference, 'cause actually I'm calling the route from a javascript submit, but is a submit, didn't it? what could I do?? If I include a form tag in the code then I had to call the function from the form button itself and then how do I handle the results out of the form... – Arthur Oct 06 '18 at 23:08
  • Just move your opening `
    ` tag up in your HTML. Maybe between your closing `` and your opening `
    `. Oh and get rid of your `style="display: none;"` from your `` tag.
    – Peter Oct 06 '18 at 23:13
  • Thanks a lot, I'll try – Arthur Oct 06 '18 at 23:21
  • Thanks It worked. Now I'm very confused about forms, do you know some good reading reference? – Arthur Oct 06 '18 at 23:33
  • https://www.w3schools.com/html/html_forms.asp is a beginner overview. Basically, all the input/select/etc fields need to be between the form tags or the don't get submitted with the form. – Peter Oct 06 '18 at 23:36