Jump to content

php help..simple question


caminator

Recommended Posts

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.

Link to comment
Share on other sites

[!--quoteo(post=352110:date=Mar 6 2006, 10:24 AM:name=Gaia)--][div class=\'quotetop\']QUOTE(Gaia @ Mar 6 2006, 10:24 AM) [snapback]352110[/snapback][/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;???
Link to comment
Share on other sites

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:

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

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

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

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.

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

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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.