Page 1 of 1

return button to index page in PHP code

Posted: Mon Aug 04, 2008 7:35 am
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?

Re: return button to index page in PHP code

Posted: Mon Aug 04, 2008 7:40 am
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.

Re: return button to index page in PHP code

Posted: Mon Aug 04, 2008 11:32 am
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.

Re: return button to index page in PHP code

Posted: Mon Aug 04, 2008 1:25 pm
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.

Re: return button to index page in PHP code

Posted: Mon Aug 04, 2008 11:04 pm
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

Re: return button to index page in PHP code

Posted: Tue Aug 05, 2008 12:26 am
by RobertGonzalez
Keep in mind that only works for browsers that have JS enabled.

Re: return button to index page in PHP code

Posted: Tue Aug 05, 2008 12:38 am
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>";
}

Re: return button to index page in PHP code

Posted: Tue Aug 05, 2008 1:30 am
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.