Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirect back to Page where submitted form

Status
Not open for further replies.

neomorpheus

Programmer
Mar 9, 2001
47
US
I have a vot eposting form. I wish to be able to go back to the page where i came from after the vote has been posted. Currently, it just displays "Vote Posted" and I have to hit the back button to get back to the original page. I do not want o hard code th epage address but use the cgi.referer. how do I do it. Please help. Much appreciated.

Code is here---


package MT::App::Vote;

use strict;
use MT::App;
use MT::Entry;
use MT::pluginData;
use Data::Dumper;
@MT::App::Vote::ISA = qw( MT::App );

sub init {
my $app = shift;
$app->SUPER::init (@_) or return;
$app->add_methods (
view => \&view,
vote => \&vote,
);
$app->{default_mode} = 'view';

$app;
}

sub view {
my $app = shift;

my $q = $app->{query};
my $entry_id = $q->param ('entry_id');
my $entry = MT::Entry->load ($entry_id) or return
$app->error ($app->translate ("Entry does not exist: [_1]", $entry_id));

my $voteData;

$voteData = MT::pluginData->load ({ plugin => 'MTVotingSystem',
key => $entry_id });
if (!$voteData) {
$voteData = MT::pluginData->new;
$voteData->plugin ('MTVotingSystem');
$voteData->key ($entry_id);
$voteData->data ({});
}

my $html = "Entry: $entry_id<br />\n";
$html .= "Total Votes: " . $voteData->data->{total} . "<br />\n";;
$html .= "Value: " . $voteData->data->{value} . "<br />\n";
$html .= "Average: " . $voteData->data->{value} / $voteData->data->{total};
$html .= "<br />\n";

$html .= "Dump: ". Dumper ($voteData->data);

}

sub vote {
my $app = shift;
my $q = $app->{query};

my $entry_id = $q->param ('entry_id');
my $entry = MT::Entry->load ($entry_id) or return
$app->error ($app->translate ("Entry does not exist: [_1]", $entry_id));

my $voteData;

$voteData = MT::pluginData->load ({ plugin => 'MTVotingSystem',
key => $entry_id });
if (!$voteData) {
$voteData = MT::pluginData->new;
$voteData->plugin ('MTVotingSystem');
$voteData->key ($entry_id);
$voteData->data ({});
}

my $data = $voteData->data;
$data->{total}++;
$data->{value} += $q->param ('value');

$voteData->data ($data);

# $voteData->data->{total}++;
# $voteData->data->{value} += $q->param ('value');

$voteData->save;

$app->rebuild_indexes( BlogID => $entry->blog_id )
or return $app->error($app->translate(
"Rebuild failed: [_1]", $app->errstr));

$app->rebuild_entry( Entry => $entry )
or return $app->error($app->translate(
"Rebuild failed: [_1]", $app->errstr));

"Vote posted.";}
 
after you print the header, write out a refresh header,
Code:
print "<meta http-equiv=\"refresh\" content=\"0:url=http://mysite.com/vote.htm\">";

I can see you're using CGI because you're reading param(''), but I can't see where you're writing out your headers

HTH
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
In yourcode, the return URL is hardcoded. How can I make that NOT hardcoded and send it back to the page it came from. (i.e the page that had submitted the form?)....the refering page.
 
The variable you are looking for is "$ENV{ 'HTTP_REFERER' }

Just redirect to that and you should be fine in most environments.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top