return button to index page in PHP code
Moderator: General Moderators
-
bazzdaciple
- Forum Newbie
- Posts: 3
- Joined: Mon Aug 04, 2008 6:45 am
return button to index page in PHP code
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?
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?
Re: return button to index page in PHP code
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
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.
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.
- 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
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:
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.
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>Re: return button to index page in PHP code
Please add this code after thank you note/send mail function
It will redirect you to 'http://www.mysite.org/index.php' page.
Thanks
Code: Select all
print "<script>";
print " self.location='http://www.mysite.org/index.php';";
print "</script>";
Thanks
- 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
Keep in mind that only works for browsers that have JS enabled.
Re: return button to index page in PHP code
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>";
}
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>";
}
- 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
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.