neomorpheus
Programmer
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:luginData;
use Data:umper;
@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:luginData->load ({ plugin => 'MTVotingSystem',
key => $entry_id });
if (!$voteData) {
$voteData = MT:luginData->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:luginData->load ({ plugin => 'MTVotingSystem',
key => $entry_id });
if (!$voteData) {
$voteData = MT:luginData->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.";}
Code is here---
package MT::App::Vote;
use strict;
use MT::App;
use MT::Entry;
use MT:luginData;
use Data:umper;
@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:luginData->load ({ plugin => 'MTVotingSystem',
key => $entry_id });
if (!$voteData) {
$voteData = MT:luginData->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:luginData->load ({ plugin => 'MTVotingSystem',
key => $entry_id });
if (!$voteData) {
$voteData = MT:luginData->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.";}