return button to index page in PHP code

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
bazzdaciple
Forum Newbie
Posts: 3
Joined: Mon Aug 04, 2008 6:45 am

return button to index page in PHP code

Post by bazzdaciple »

hello all!
I have a PHP code that can be used for contact forms. In the end, when the visitor of my page has inputted his name, e-mail and message content en clicks on SEND the mail is send to my mailaccount. so fas so good, but then a echo message is displayed thanking the person for sending his mail. At that point I would like to see below that remark a button which will lead the visitor back to my homepage (index). There now is a link, with javascript, sending the person back one page, which again is the contact form. But I need the person to go back to the index.

What PHP code should I use for the link?
Dynamis
Forum Contributor
Posts: 122
Joined: Thu Jul 10, 2008 3:15 pm
Location: Indiana, US

Re: return button to index page in PHP code

Post by Dynamis »

What you have said is very vague. If you have javascript to send him back one page, you should be able to change the page it is going back to, to your index page instead. If not, you just make a simple link to go back to index. There isn't much more I can tell you without seeing your code or getting a better understand of how you are having a problem.
bazzdaciple
Forum Newbie
Posts: 3
Joined: Mon Aug 04, 2008 6:45 am

Re: return button to index page in PHP code

Post by bazzdaciple »

hi Dynamis

terrible sorry I can't be more informative. I'm at work at the moment and don't have access to the code.
I was hoping I would get a answer this afternoon so I could work on the page later on.
all I know is that the code says something like:
<a href="javascript:history.back()"

so when I click on this link (after back() it says the word BACK which is shown on the screen as a link) it only takes me back one page, while I would like this link to bring me back to any page I want. Preverebly the index (home) page. I tried deleting this line and putting in a regular link but for some reason that presented me with a error code.
Hope this helps, if not I will post the script this evening.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: return button to index page in PHP code

Post by RobertGonzalez »

Put a check in your code somewhere that will see if a button named something is set in the post array. If it is, redirect them. Something like:

Code: Select all

<?php
if (!empty($_POST['sendhome'])) {
  header('Location: http://homepage.com/');
  exit;
}
 
// Handle the rest of the posted form data and echos here, along with your form button
?>
<form action="<?php echo basename(__FILE__) ?>" method="post">
<input type="submit" name="sendhome" value="Return Home" />
</form>
So, first run user sees a form. If the form is posted and successful, the user sees the above button. If the button is sent back to the page then the user is redirected back to your homepage.
coder500
Forum Newbie
Posts: 20
Joined: Fri Jul 25, 2008 10:24 am
Location: Singapore

Re: return button to index page in PHP code

Post by coder500 »

Please add this code after thank you note/send mail function

Code: Select all

 
print "<script>";
print " self.location='http://www.mysite.org/index.php';"; 
print "</script>";
 
It will redirect you to 'http://www.mysite.org/index.php' page.
Thanks
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: return button to index page in PHP code

Post by RobertGonzalez »

Keep in mind that only works for browsers that have JS enabled.
mani8php
Forum Newbie
Posts: 1
Joined: Tue Aug 05, 2008 12:06 am
Contact:

Re: return button to index page in PHP code

Post by mani8php »

Hello,

U just put one anchor tag in the "your mail sent successfully Page" in that anchor link u just pass the index page url or what url u need..

that is.,

if($mail)
{
echo 'your mail sent successfully';
echo "<a href=index.php >MOve to Index</a>";
}
else
{
echo 'your mail Not sent successfully';
echo "<a href=contact.php >MOve to Contact</a>";
}
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: return button to index page in PHP code

Post by RobertGonzalez »

Please use PHP tags when posting code in the forums. It is not that hard and it makes really easy for everyone else to read.
Post Reply