Pass information between two PHP pages

2

Good afternoon! I'm having the following problem: I have a php page named locality that has the fields "name" and "city". In the name field, I type the name of the locality, such as "Beautiful Corner", and in the city field I retrieve from a table tebelaCidades . It turns out that when I click the "Search" button, through the url of the controller, the page that contains the cities table is accessed, that is, if before the link was link , it now becomes link . When I click select, the data is loaded into the city input correctly, but whatever the name I typed in the name field returns empty. I know that as I call the page location to enter the city data, then the page is rendered and then every field that had been filled, back empty. So the question is: how can I solve this problem?

Note: I'm using the Laravel framework (Blade template engine).

Thank you in advance.

    
asked by anonymous 23.10.2017 / 19:12

1 answer

0

On the button put an onClick event like this:

 <a onclick="procuraPelaCidade()">

Create a simple javascript

function procuraPelaCidade(){
   var nome = document.getElementById("#idDoCampoNome").value;
   var cidade = document.getElementById("#idDoCampoCidade").value;
   window.location = "jfsjunior.tcc.sistema/localidade/"+cidade+"/"+nome;
}

If you are using laravel, you can pass the data you need by route. For example,

Route::get('jfsjunior.tcc.sistema/localidade/{cidade}/{nome}',['as'=>'localidade.view', 'uses'=>'nomeDoController@view']);

It does not have to be exactly like this, you can pass the name of the city and name, as you wish, is just an example.

Within theController name, do a function like this:

 public function view($cidade, $nome){
   return view('tela-localidade', compact('cidade','nome'))
 }

Create a new web page-locality.blade.php or change that same page to with inputs like this:

  @if($cidade != null)
  <input id="idDoCampoCidade" value="{{$cidade}}">
  @endif
  @if($nome != null)
  <input id="idDoCampoNome" value="{{$nome}}">
  @endif

It would actually be easier to use an ajax, but I think it works that way, too. If you have a bug in my code, start with the idea of redirecting pages by javascript, simple. Create a route with the desired parameters. Manipulate forwarding with values passed within the route controller. Treat these values with the blade.

    
24.10.2017 / 02:24