php – Page redirect with error message

Question:

Good afternoon I have a doubt this command is correct?

http://localhost/site/index.php#contato?info=Email%20Vazio

index.php#contato?info=Email%20Empty

This is the function that sends the command but the page is at the top and the message no longer appears on the form.

private function setNome($nome){
    if(!empty($nome)){
    $validar = new Validar($nome);
    $this->nome = $validar->getValidado();
    }else{
    $this->setError("Nome Vazio");
    return print "<script language='JavaScript'>location.href='"
    . "index.php#contato?info={$this->getError()}'</script>";
    exit();
    }

If I remove the #contato , it works but I would like it to go straight to the form so that the user doesn't have to #contato down the whole page again with every typo

Answer:

Adriano! uses the php header() function, with it you do this redirect.

Ex:

Header(location: 'www.google.com.br');

Scroll to Top