Jump to content


Photo

Redirecting!


  • Please log in to reply
17 replies to this topic

#1 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 01 October 2006 - 04:15 AM

I have a form that leads to a script to be emailed. When the person submits the form and goes to the script page I want to have them redirected to another page and I know it's possible but I just can't figure it out. So basically how do I make a page go to another page once someone views it?

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 01 October 2006 - 04:17 AM

header("Location : newpage.php");

Be aware however thast no output can be sent to the browser before calling the header function.

#3 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 01 October 2006 - 04:20 AM

do you mean if i have the redirect code in the script then i can't send the email? and where would i put the line?

#4 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 01 October 2006 - 04:25 AM

isnt there a way i could do the if..else stament if it was mailed have it go to a url and if it wasnt have to say something?

#5 extrovertive

extrovertive
  • Members
  • PipPipPip
  • Advanced Member
  • 235 posts

Posted 01 October 2006 - 04:39 AM

if(mail(...)) header("Location: http:///www.domain.com");
else {
//something
}

#6 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 01 October 2006 - 07:38 AM

do you mean if i have the redirect code in the script then i can't send the email? and where would i put the line?

no you can do a mail function. you just can't have any html output before a header. example:

mail(...);
header(...);

is fine.

mail(...);
echo "blah";
header(..);

is not.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#7 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 01 October 2006 - 09:18 AM

Output control could fix that problem:

http://php.net/outcontrol

#8 JasonLewis

JasonLewis
  • Members
  • PipPipPip
  • Advanced Member
  • 3,351 posts
  • LocationVictoria, Australia

Posted 01 October 2006 - 09:31 AM

or if you want to put output simply put this at the top of your code then at the bottom:

ob_start();

<---
CODE
--->

ob_end_flush();

Good luck with your coding.
Jason / ProjectFear / Jaysonic

#9 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 01 October 2006 - 09:31 AM

I just said that...

#10 JasonLewis

JasonLewis
  • Members
  • PipPipPip
  • Advanced Member
  • 3,351 posts
  • LocationVictoria, Australia

Posted 01 October 2006 - 09:35 AM

lol. soz i didnt c that. and with mine they dont have to go to a site. :D i'll look next time. sorry.
Good luck with your coding.
Jason / ProjectFear / Jaysonic

#11 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 01 October 2006 - 03:26 PM

Okay thanks. In this code.
if(mail(...)) header("Location: http:///www.domain.com");
else {
//something
}
I would put
if (mail($to;$message;$subject;$header)) header ('Location: http://www.redirectpage.com')
else {
echo "there was a problem"
}
is that how i should do it?

#12 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 01 October 2006 - 03:34 PM

Yeah, but it would have to be
mail($to,$message,$subject,$header)
since you seperate arguments with commas.

#13 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 01 October 2006 - 04:03 PM

okay, im getting a few problems...
this is my code that should send an email and redirect to another page
<?php
ob_start();
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$to = "(my-email)";
$subject = "Selling Chips";
$message = "<b>$name</b>'s comment.---$comment.";
$headers = "From: $email";
mail($to,$subject,$message,$headers);
if (mail($to,$subject,$message,$headers)) header("Location: thankyou.php");
else "echo A problem occured";
ob_end_flush();
?>
is that right? because i get this page coming up.. its the page that the form was directed to with a warning at the top...
Warning: Cannot modify header information - headers already sent by (output started at /home/content/j/w/k/jwk811/html/process.php:5) in /home/content/j/w/k/jwk811/html/process.php on line 37

And actually get sent two emails so the if (mail...) is actually sending me another.. whats the problem? cant figure it out


#14 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 01 October 2006 - 04:14 PM

okay that script in and of itself does not need the ob_start/ob_end_flush functions.  Is this script a code block in a larger script, or is it being included in another script? If so, again, there cannot be any html output before the header.  you will have to extend your ob stuff to include the other stuff.

If this script is in its own file and it's not being included into something else, then check to make sure you don't even have a blank line before your <?php tag, cuz that counts as html output
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#15 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 01 October 2006 - 04:28 PM

Thank you very much. But just one more thing.. the if(mail..) is sending me another email.. i got the redirect to work now but what about the email and if something did go wrong would the else stament say the error if the if thing isnt going right?

#16 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 01 October 2006 - 04:34 PM

you are getting 2 emails because you are sending 2 emails.

mail($to,$subject,$message,$headers); // take out this line
if (mail($to,$subject,$message,$headers)) header("Location: thankyou.php");
else echo "A problem occured";

you need to take one of them out. i suppose you should take out the first one, so as to leave in some error handling. Also on your else statement, move the " you have your quotes wrapped around echo.  (I changed it in the code I listed, for reference).
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#17 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 01 October 2006 - 04:41 PM

okay thanks ive got it now. how would i be able to make it so it won't redirect if they forgot to type in there name, email, etc?

#18 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 01 October 2006 - 04:49 PM

you need to setup some error checking for your form. wrap that thing inside some more conditioning.

VERY basic example:
if (!$_POST['name'] or !$_POST['email']) {
   echo "please fill out your form";
else {
  if (mail($to,$subject,$message,$headers)) header("Location: thankyou.php");
  else echo "A problem occured";
} 

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users