PHP = Send Message + Message Thanks + (button) or refresh

Asked

Viewed 161 times

0

Boas, I am bicão and I keep moving in my site I would like the help of you s:

After the customer sent message appeared white screen with message of thanks. I fixed to return to the site but the message disappeared.

echo   "$nome,  Email enviado. Breve entraremos em Contato!";

header("Location: http://www.xxxxx.com.br");

I’d like to put a echo or script (I’m already familiarizing myself with the terms rs) thanks and the page return to the site alone.

Already tried some things copied and adapted from the internet

(<script language="JavaScript" charset="utf-8">alert("$nome,  Email enviado. Breve entraremos em Contato!")</script>
<meta HTTP-EQUIV='refresh' CONTENT='4; URL= http://www.xxxx.com.br '>) 

but it didn’t work

I tried to

<script> alert(  "$nome,  Email enviado. Breve entraremos em Contato!)"; </script>”
header("Location: http://www.xxxxx.com.br");

Didn’t work

I tried to

echo “<script language="JavaScript" charset="utf-8">alert("$nome,  Email enviado. Breve entraremos em Contato!")</script>
<meta HTTP-EQUIV='refresh' CONTENT='4; URL= http://www.xxxxx.com.br '>

Didn’t work

Imagem mostrando as tentativas

2 answers

0

I can’t quite understand your code, but I think I understand your purpose.

First take care of that character it’s not create string like this one ", it will generate an error which can make you take a while to discover that was this character.

Now let’s get to the problem, from what I understand you want the user to go back to a particular page after some time, for the user to see the email message sent.

This PHP code should not work for your case:

header('Location: http://www.example.com/');

The above code sends a header indicating to the browser that it should go to another link, so the user does not get to see the HTML.

If you want to do this via header you can use the Refresh adding url= as in the example below:

/// 10 indica o tempo em segundos
header("Refresh: 10; url=http://minhapagina.com");

/// Agora se eu não estou enganado você tem que
/// colocar esse código antes de escrever algo
/// na página, ou seja, antes do seu echo.
/// Caso contrário acho que ele gera um notice ou warning.

You can also do this via javascript, using the setTimout to wait a while and the location.href to redirect the user, as shown below.

/// O número 10000 esta em milisegundos e indica o 
/// tempo que deve esperar para chamar a função
setTimeout( function(){
    location.href = "http://minhapagina.com";
}, 10000 );

Now how do I realize that you are writing this code within the PHP code area or within the tags PHP <?php ?> or <? ?>, below is the code generated with echo

echo "<script>";
echo "setTimeout( function(){";
echo "location.href = \"http://minhapagina.com\";";
echo "}, 10000 );";
echo "</script>";
  • this refresh tip combined with what I already had was PERFECT. header("Refresh: 10; url=http://minhapagina.com"); Thanks, bro.

0

Hello, with the following function

(<script language="JavaScript" charset="utf-8">alert("$nome,  Email enviado. Breve entraremos em Contato!")</script><meta HTTP-EQUIV='refresh' CONTENT='4;URL=http://www.xxxx.com.br'>)

You cannot print the name of the person by the variable "$name" this with the PHP syntax, what you could do is create a variable in Javascript and assign to this function in this way

<script type="text/javascript>
let nome = nome enviado pelo usuário
alert(nome+',  Email enviado. Breve entraremos em Contato!');
window.location="http://google.com/";
</script>
  • Olympius, Thank you for your help.

Browser other questions tagged

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