address via get

1

My query is the following, I need to address to the same page that is created in php with html code, and within it I have a validation form via post, when I send the post to the same page that is index, valid those fields with php, then if there is an error I do a header location to the same page where I send via get an? id = error, but when the page is reloaded it remains in the beginning and I need to go down to the id where is the form . How can I do it?

<?php 
if(empty($_POST['usuario']))
{
header("Location:index.php?id=contacto&num=1");
?>
?>
codigo principal.....
<!-- formulario de contacto 60 lineas mas abajo -->
<div id="contacto">
    <form method="POST">
<?php
if(num=="1")
{
   //muestro mensaje de error
}
?>
    <input name"usuario">
    <input type="submit">

Well that's the idea, thank you in advance.

    
asked by dogdark 17.09.2017 в 00:49
source

2 answers

1

Use anchors next to your variables, add to the end of the #contact link ( id of the div that contains the form):

Solution

header("Location:index.php?id=contacto&num=1#contacto");

Ref: link

    
answered by 17.09.2017 / 21:29
source
0

good friend you can use the following code to show the notice on the page when the request was sent by the form as follows:

  

where the variable of the get of the header "num" is received by the $ _GET of the id and it shows what you need

<?php if(empty($_POST['usuario'])) { header("Location:index.php?id=contacto&num=1");}?> codigo principal..... <!-- formulario de contacto 60 lineas mas abajo --> <div id="contacto"> <form method="POST"> <?php if($_GET["num"]=="1") { /*muestro mensaje de error*/ } ?> <input name"usuario"> <input type="submit">

The other simpler would be like this:

<?php if(empty($_POST['usuario'])) { $msg="<h3>este es un error</h3>";}?> codigo principal..... <!-- formulario de contacto 60 lineas mas abajo --> <div id="contacto"> <form method="POST"> <?php if(!empty($msg)) {echo $msg; /*muestro mensaje de error/* } ?> <input name"usuario"> <input type="submit">
  

where the message is simply set by means of the variable "$ msg" and printed when the same is true so to speak after it is activated.

    
answered by 17.09.2017 в 06:44