Page redirection with error message

Asked

Viewed 57 times

3

Good afternoon I have a doubt this command is correct?

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

index.php#contact? info=Email%20Vazio

This is the function that sends the command but the page is at the top and the message no longer appears in 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();
    }

Should I withdraw the #contato, works but I’d like it to go straight to the form so that the user doesn’t have to scroll down the entire page again at each typing error

  • 1

    It’s the opposite: first comes the query and then Fragment; see the format in this question: https://answall.com/q/228220/64969

  • 1

    The #contact anchor should come after the parameters. Test like this: http://localhost/site/index.php?info=Email%20Vazio#contato

  • worked out thanks

1 answer

0

Adriano! uses php’s header() function, with it you make this redirect.

Ex:

Header(Location: 'www.google.com');

Browser other questions tagged

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