PDA

View Full Version : how to redirect a page.


0810
08-27-2002, 05:57 AM
hi how are you? I just like to know how I can show only text "thank you for filling my form" to next page when I click send's button. Also if you don't fill out mail box, it comes message like "Fill out your E-mail".

Now even though I click send button, it doesn't go next page. Just come up text("thank you for filling my form") under the form in the same page.


I would like to do next page






here is code

<html>
<head>
</head>
<body>
<p>Enter whatever</p>


<form method="post" action="itohideo.php">

Name<input type="text" size="80" name="msg"><br>
E-mail<input type="text" size="80" name="mail">
<br>
Password<input type="text" size="80" name="password"><br>
<input type="submit" name="submit" value="Send">
<input type="reset" name="reset" value="reset">
</form>

<?php


if(isset($_POST["submit"]))
{

$msg=$_POST["msg"];
$mail=$_POST["mail"];
$password=$_POST["password"];

$fp=fopen("log.txt","a");

if(!$fp)
{
print("Can't open your file'");
exit;

}
fwrite($fp,"*******************************************************\r\n\r\n");
fwrite($fp,"Name:\t\t\t$msg\r\n");
fwrite($fp,"E-mail:\t\t$mail\r\n\r\n");
fwrite($fp,"Password:\t\t$password\r\n\r\n");

fclose($fp);

print("Thank you for filling out my form<br>\n");

}



?>
</body>
</html>

freakysid
08-31-2002, 12:57 PM
Your form data is being sent to itohideo.php. So it is that file which will have to either send back the html you wish your user to see next, or redirect the user to the page you want them to see after they submit.

<?php

// we have processed the form data now
// we will send the user to foo.html

header("Location: foo.html");

...

(big caveat - you cannot send out any output back to the browser (includeing white space before the <?php tag) before sending your header).

As for checking that the user entered their email - this you can easily do on the client (browser with javascript).

<html>
<head>
<script language="javascript">
function doFoo() {
if ( ! document.foo.mail.value.length ) {
alert('Hey pal! What\'s your email?');
return false;
}
return true;
}
</script>
</head>
<body>

<form name="foo" method="post" action="itohideo.php">
Name<input type="text" size="80" name="msg"><br>
E-mail<input type="text" size="80" name="mail">
<input type="submit" name="submit" value="Send" onClick="return doFoo();">
</form>

</body>
</html>