Page 1 of 1
get variable from form and create redirect url
Posted: Sat Jan 27, 2007 12:48 am
by SmokyBarnable
I'm trying to make a simple page that has an html form where the person enters their email address and clicks submit. How could I take the email they enter and assign it to a php variable? I then want to create a url based on the email input and have a redirect so when they click submit it would redirect to the url created. Are there any examples of this anywhere?
p.s. what would cause a headers already sent error when using
Thanks for any guidance.
Posted: Sat Jan 27, 2007 3:11 am
by jyhm
Try this javascript redirect in your page:
Code: Select all
<script type="text/javascript">
<!--
function delayer(){
window.location = "http://www.example.com"// replace with your page or a variable.
}
//-->
</script>
And on the same page as this javascript write:
Code: Select all
<body onLoad="setTimeout('delayer()', 5000)">
<p><b>Thank you <br />your message:</b></p>
<p><br /><b>Has been sent from:</b><br />email@example.com</p>
<p> If your page does not redirect in 5 seconds
<a href="http://www.example.com">click here</a></p>
The header error occurs when that php script is called after page information is already declared. It is best to use before even the doctype declaration I believe. So if in your code you are unable to achieve this you can use the above javascript redirect.
As far as your question about forms and php variables are concerned, it is a simple matter of using POST or GET which ever method that you specify in your form. With out seeing your code this is the best demo I can give. On the page that receives the form info start with these lines.
Code: Select all
<?php
// Use $_GET if GET is specified in your form method.
if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['message'])) {
$name=$_POST['name'];
$email=$_POST['email'];
$message=$_POST['message'];
}
// More php code etc,..
?>