Pass information between two PHP pages

Asked

Viewed 182 times

2

good afternoon! I’m having the following problem: I have a page named php locality which has the fields "name" and "city". In the name field, I enter the name of the locality, as for example, "Beautiful Corner", and in the city field I recover from a table thence. It turns out that when I click on the "Search" button, through the controller url, the page containing the city table is accessed, ie if before the link was http://jfsjunior.tcc.sistema/localidade/cadastro, now becomes http://jfsjunior.tcc.sistema/cidade/pesquisaCidade/tela-localidade. When I click select, the data is loaded into the city input correctly, but what name I entered in the name field comes back empty. I know that as I call the page locality to enter the data of the city, then the page is rendered and then every field that had been filled, turn empty. So the question is, how can I solve this problem?

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

From now on I thank.

  • I think the problem is in the construction of the application. You send it to another page to search the location and then return to the same page with the data filled in? Wouldn’t it be better to use AJAX?

  • Because it’s @Wallace Maxters, I’ve been told this, but I don’t have much knowledge about ajax, and unfortunately I don’t have time (tcc)to study Ajax, then published with the hope that someone had gone through something similar and could share their achievements or how they managed to solve the problem.

1 answer

0


On the button put an onClick event like this:

 <a onclick="procuraPelaCidade()">

Create a javascript simple

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

If Voce is using Laravel, you can pass the data you need along the route. For example,

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

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

Inside the nameController make one Function thus:

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

Create a new screen-locale.blade.php page or change that same page to inputs like this:

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

It would really be easier using an ajax, but I think it works as well. If you have a code failure of mine, start from the idea of redirecting pages by javascript, simple. Create a route with the desired parameters. Manipulate the redirect with values passed inside the route controller. Treat these same values by Blade.

  • then, I would capture the data from the locality page, do the search on the Age page and then upload the locality page with the previously captured data along with the selected city? But in this case, if it’s more than two dice? So, and I have other screens with the same problem and have more fields (I indicated the locality for being simpler). It would be complex to url no?

  • You can pass multiple values by the url yes, or this value passed can be a json or array. If I’m not mistaken. You only need to make the routes in the Routes folder, in the web.php file accept values in the url. And then manipulate the method responsible for building the page. Understood?

  • Got it... so can I pass an array by the url? Then I think it looks better... I will search and implement and put the result!

  • From a look here: https://laracasts.com/discuss/channels/laravel/not-able-to-pass-this-array-to-controller-through-route And here too: https://stackoverflow.com/questions/359419/laravel-redirectroute-with-an-array-parameter

  • I hope I’ve been of some help

  • 1

    Thank you João V. Araújo!

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.