Jump to content


Photo

php help..simple question


  • Please log in to reply
4 replies to this topic

#1 caminator

caminator
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 06 March 2006 - 04:11 PM

Hi guys...newbie here.

I have my site built with php and html. I have header.php and footer.php. These are includes in every page. Anyway, here is my problem.

I have this poll on my site that I put on. My poll is part of footer.php. I want it to be included in every page so that is why I put it there. When I hit 'Vote' to submit my vote on the poll, the poll takes me to footer.php. I want it to go back to whatever page the person was viewing before they hit Vote. footer.php isn't a real "page", so when it forwards to it after pushing the Vote button, it loses all formatting and design.

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]function poll() {
global $POLLTBL, $CLASS, $HTTP_SERVER_VARS;
$this->tbl = $POLLTBL;
$this->poll_view_html = array();
$this->poll_result_html = array();
$this->options = array();
$this->options_text = array();
$this->poll_question = array();
$this->form_forward = '';
$this->template_set = '';
[/quote]

This is part of my code that I think needs changing from reading around, but Im not sure what to change.

here is [a href=\"http://www.caminator.com\" target=\"_blank\"]My Webpage[/a]. Feel free to go and 'test' it and you will see waht I am talking about.



#2 Gaia

Gaia
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts
  • LocationCanada

Posted 06 March 2006 - 05:24 PM

Maybe put in something like HTTP_REFERER so that you can save where they came from and then send them back?

#3 caminator

caminator
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 06 March 2006 - 05:53 PM

[!--quoteo(post=352110:date=Mar 6 2006, 10:24 AM:name=Gaia)--][div class=\'quotetop\']QUOTE(Gaia @ Mar 6 2006, 10:24 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Maybe put in something like HTTP_REFERER so that you can save where they came from and then send them back?
[/quote]


Do you mean it would look something like this then?

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]function poll() {
global $POLLTBL, $CLASS, $HTTP_REFERER;
$this->tbl = $POLLTBL;
$this->poll_view_html = array();
$this->poll_result_html = array();
$this->options = array();
$this->options_text = array();
$this->poll_question = array();
$this->form_forward = '';
$this->template_set = '';
[/quote]

just change the _SERVER_VARS to _REFERER;???

#4 txmedic03

txmedic03
  • Members
  • PipPipPip
  • Advanced Member
  • 313 posts
  • LocationCall, TX, USA

Posted 07 March 2006 - 10:32 PM

No not at all. What was meant by using $_SERVER['HTTP_REFERER'] is something like if you have poll.php which contains your poll and you have writepoll.php which is where your information gets sent then you could have a message that upon success says:

echo "Thanks for your opinion, click <a href=\"".$_SERVER['HTTP_REFERER']."\">here</a> to return to where you came from.\r\n";

You could use a redirect if you have not sent output to the browser already like this:

head("Location: ".$_SERVER['HTTP_REFERER']);

A javascript redirect would do the job too, but let's concentrate on the PHP solutions since some people disable javascript in their browser and we want the pages to be as universal as possible.

Now if your poll.php is the poll as well as the file that will process it you could do something like this.

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
  {Poll form elements go here per usual}
</form>

This will submit the value(s) to the current page and then poll.php can process them. Make sure your code to process the form is placed above the form in you poll.php file so you can pick whether to display the poll or perhaps a print out of the votes cast so far. Also be aware if you have other forms on any of your pages that your scripts must be able to determine if they are the one being submitted or not. If you use the $_SERVER['REQUEST_METHOD'] to determine if the form was posted and two forms on the page were both using "POST" method things could get a little tricky.

I hope I have pointed you in the right direction, but if not, please, let me know I will try to rectify the situation.

Happy coding!

SEMPER FIDELIS!

I can't stop you from doing something silly, but at least I can help you do it right.


#5 caminator

caminator
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 08 March 2006 - 01:10 AM

Thanks so much for the awesome reply. I will take a look at it either later tonight or tomrrow and see if I can figure out what you are talking about. Thanks again for all the detail. I'll keep ya posted on how it goes.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users