input form does not type

Asked

Viewed 91 times

-2

but where you type the zip code, you’re not typing anything, how do I rescue the zip typed in a variable with $post ? and in the calculus I wanted to redirect to calculus.php,something similar to this:

<input name="postok" type="button" id="postok" value="Calcular" onClick="calculoFrete();"> 

someone can help?

here is the code:

echo'<form action="" method="post">';
echo'<tr><td colspan = "4" bgcolor = "ffffff"></td align = "center"><h4>Tipo de Entrega&nbsp;<select id = "tipo" name = "tipo" title = "Servicos dos Correios" class = "select" tabindex = "1"></h4><option value = "PAC" style = "font-size: 25px;">PAC</option><option value = "SEDEX" style = "font-size: 25px;">SEDEX</option>
</select><br />Informe aqui o Cep para calcular o frete:<input name="cepDestino"  style = "font-size: 18px;" autocomplete = "off" type="text" id="cepDestino"><br /><td>';
echo'</td><input type = "submit" id = "pesquisar" name ="pesquisar"  style = "font-size: 18px;" autocomplete = "off" tabindex = "2" class="button" value = "calcular"/></form></td';
echo '<tr>';
  • always include source code in your questions

  • If you are not using ajax, you have to set the form destination in the action: <form action="calculo.php" method="post">

1 answer

1

To rescue the zip typed in a form with the html input tag you need to use the PHP language feature which is called superglobal variables. Superglobals are available in all scopes, so you can set a normal variable so that it receives a superglobal.

For example:

$cep = $_POST['input_cep'];

There are a lot of superglobal variables, it’s up to you which one to use. For example, you could use $_GET if it was a GET request; or even $_REQUEST, it works with all kinds of requests.

Remember that the ones I mentioned are associative arrays, because they can be accessed by numerical or textual indexes. In this case the index will be the name attribute of your txt input.

If you want to redirect to another PHP page via a button, you need to specify this at the opening of the tag form.

For example:

...

Then you can give an echo to display the $cep variable.

Browser other questions tagged

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