POST data not being 'reposted' on a second page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tjk2009
Forum Newbie
Posts: 2
Joined: Mon Dec 05, 2011 4:34 pm

POST data not being 'reposted' on a second page

Post by tjk2009 »

hello,

i have tried to create a 'send to friend' form for my website using php, to which i am somewhat new. the idea is that someone can click a link on any page and a pop-up window will ask them for their info and that of their recipient and then send an e-mail with that specific webpage's title and URL. i have gotten everything to work, except for the most crucial thing -- the e-mail that sends does not include the title/URL. i believe this is because the PHP form is not passing along the info from the original webpage.

here's an example from 'Sample webpage (sample.htm)':

Code: Select all

<form method="post" action="sendtofriend.php">
<input type="hidden" name="title" value="Sample webpage">
<input type="hidden" name="url" value="sample.htm">
<input type="submit" value="Send to friend">
</form>
this takes us to the sendtofriend.php pop-up, which contains this code:

Code: Select all

<?php
 if (isset($_REQUEST['email']))
	{
	$title = $_REQUEST['title'] ;
	$url = $_REQUEST['url'] ;
	$email = $_REQUEST['email'] ;
	$sender = $_REQUEST['sender'] ;
	$recipient = $_REQUEST['recipient'] ;
	$subject = $_REQUEST['subject'] ;
	$comment = $_REQUEST['comment'] ;
	$message = $sender . "wanted to send you this link: " . $title . " (" . $url . ")"
His/her comment: " . $comment ;
	$from = "" . $sender . " <" . $email . ">";
	$headers = "From: " . $from;
	mail($recipient, $subject, stripslashes($message), $headers);
	echo "Sent!";
	}
 else
	{
	echo "<form method='post' action='sendtofriend.php'>
<input type='hidden' name='subject' value='From a friend'>
Name: <input type='text' name='sender' size='40'><br>
Your e-mail: <input type='text' name='email' size='40'><br>
To: <input type='text' name='recipient' size='60'><br>
Comment: <textarea cols='60' rows='4' wrap='hard' name='comment'></textarea><br>
<input type='submit' value='Send to friend'>
</form>";
	}
 ?>
(i have edited down the code above to include just the relevant info.) as i wrote, i think the problem is that when this form (sendtofriend.php) is submitted, it does not retain and pass along the info it received from sample.htm. i have struggled with this for a few days now with no success. is there a way to keep that info in its 'memory'? i know that this could be avoided by putting the whole form in the original page (sample.htm), but the idea is that i would not have to put it in every single webpage, but rather, could have all the webpages link to one standard 'send to friend' form.

thanks for any help in advance!
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: POST data not being 'reposted' on a second page

Post by social_experiment »

Have you tried using $_POST as opposed to $_REQUEST?
tjk2009 wrote:is there a way to keep that info in its 'memory'?
Yes, you could use sessions to carry information from page to page
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
tjk2009
Forum Newbie
Posts: 2
Joined: Mon Dec 05, 2011 4:34 pm

Re: POST data not being 'reposted' on a second page

Post by tjk2009 »

hello,

thanks for the response. i had tried using $_POST (as well as $_GET), but it did not work either. the problem with sessions, i think, is that the referring page is not PHP, but HTML. do you have any other idea what might work?

thanks!
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: POST data not being 'reposted' on a second page

Post by social_experiment »

Can you paste the results you receive if you use $_POST? You submit the form as usually but on the 'sendtofriend.php' you only have the following

Code: Select all

<?php
 echo '<pre>';
 print_r($_POST);
 echo '</pre>';
?>
The script seems fine, unless there is something in the code you didn't paste
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply