When voting on a node, the form uses the POST method. This is good. As a change is being made on the server in response to the HTTP Request, this is the right method to use according to the RFC.

However, this does introduce a niggle or two. Happily this should be easy to fix as I try to explain below.

If one wishes to refresh a node after voting on it (to see, for example, if there are any new replies) most browsers will warn the user that they are resubmitting POST data (also a good thing).

Additionally, since the request was made using POST, the URL the browser has visited doesn't include the node id. This makes it troublesome to bookmark the page, or copy/paste the URL to tell somebody else about the node.

  1. Hey. Great answer!
  2. Up vote
  3. Hmm, that will solve Bob's problem. Email a link ... oh.

However, this should be a pretty easy thing to fix (depending on how the modified Everything code that PM runs on is set out). Simply issue a 302 redirect back to the node page after making the changes on the server.

Such code might look something like this (untested):

use strict; use warnings; use Apache::Constants qw(:common REDIRECT); use Apache::Request; # Update. See said it was untested! sub handler { my $r = shift; $r = Apache::Request->instance($r) my $op = $r->param('op'); if (defined $op && $op eq 'vote') { # # Insert code to record votes here # my $node_id = $r->param('node_id') || ''; my $location = "http://" . $r->hostname . "/?node_id=$node_id"; $r->header_out('Location' => $location); return REDIRECT; } # Otherwise carry on and display the page as normal }

Replies are listed 'Best First'.
Re: Redirect after post for happy bookmarking and refreshing
by Joost (Canon) on May 26, 2005 at 13:12 UTC

      True, there are ways around it. It isn't a major problem, although perhaps I didn't convey that in my post. It is an annoyance that you have to take that extra step though, and it should be a pretty easy thing to fix (as my code demonstrates) and make PM that little bit nicer.

Re: Redirect after post for happy bookmarking and refreshing (easy)
by tye (Sage) on May 26, 2005 at 16:49 UTC

    Yep, pretty trivial stuff. Oh, except for that one part:

    # # Insert code to record votes here #

    Yeah, just that little bit of code that pretty much runs the whole site, the whole framework that just doesn't cut'n'paste into such a block very nicely. :)

    The only "pretty easy" routes would be to either: A) render the whole page as usual and then, at or near the "last minute", throw all of that work away and instead output a redirect which would then have to render everything all over again; B) do something like you've written but try to yank aside the bits of processing that are required by the vote-casting code (parsing the cookie, loading your user information, the node cache, etc.). Note that (A) also presents a specific problem of rendering the XP Nodelet but then not displaying it; which means someone might miss an announcement of having gained new level powers (not a horrid problem, but something worth avoiding).

    Actually, you are only talking about "vote", not any of the other POST situations at PerlMonks. Voting is handled by an opcode, which gets run fairly early in the whole request processing line, so we could switch to a redirect right after that if voting was POSTed. However, I believe we have forms that mix voting with node updates so we'd have to look into whether those would be messed up by such a change.

    I'd rather do something like this for all POST operations -- why "fix" voting but not chatter, node creation, node updates, consideration, etc. But, despite assumptions about how easy something like this must surely be, I'm not convinced that it actually is easy. Certainly, it isn't trivial for me to even work out an easy way to implement it that I'm sure will work without some unfortunately consequences.

    I encourage the appointed to look into such a scheme. I've outlined some possible approaches and some potential problems, so there might be a useful starting point there.

    - tye        

      Yeah, just that little bit of code that pretty much runs the whole site, the whole framework that just doesn't cut'n'paste into such a block very nicely.

      I knew there was a I reason I added the depending on how the modified Everything code that PM runs on is set out qualifier ;)

      Actually, you are only talking about "vote", not any of the other POST situations at PerlMonks.

      Simply the usecase I'd encountered, its useful as a general pattern for many post operations. Hmm, pattern, I wonder what google has to say about it.

Re: Redirect after post for happy bookmarking and refreshing
by davidrw (Prior) on May 26, 2005 at 13:38 UTC
    I also encounter this when moderating a node, too -- either aproving or voting on a consideration (granted these cases happen a lot less often then the voting case).

    Anyways, I do the same thing as Joost and just click on the node id in the title.. An alternative would be to put something like [id://`id`|THIS NODE] in your Free Nodelet Settings.
Re: Redirect after post for happy bookmarking and refreshing
by halley (Prior) on May 26, 2005 at 13:39 UTC
    Personally, I'd like to see the voting system go the way of AJAX, with instantaneous submission without leaving the current page at all. NetFlix's voting (1 to 5 "stars") is perfect: you can click any star anywhere and it won't lose your place as you browse.

    --
    [ e d @ h a l l e y . c c ]

      I'd like to see the voting system go the way of AJAX

      I like that idea, but there would still have to be some way to confirm your vote, otherwise I could see accidentally voting the wrong way. It might be a hard sell on the devs, though. I have heard from a few that they try to maintain browser compatibility at nearly all costs. I don't really know how I feel about this policy, but that's what it seems to be.

        I disagree that there should be a confirmation. I personally think that WAY too many user interfaces treat users like idiots and require confirmation on the most trivial of tasks.

        Sure, confirm before something VALUABLE is irrevokable, but a vote on a single writeup on PerlMonks? Cripes. You get several per day, and if you think you clicked the wrong button, make it up to the author on their next writeup. You don't need to confirm every little worthless thing, even if it's a permanent worthless thing.

        --
        [ e d @ h a l l e y . c c ]

Re: Redirect after post for happy bookmarking and refreshing
by belg4mit (Prior) on Jun 12, 2005 at 10:35 UTC
    Yeah it kinda sucks, but try training yourself to bookmark then post? Use back button? Or an alternative half-fix might be to append node_id to the form action URI?

    UPDATE: Test action with appended node_id, well it worked but there's a pparently already a redirect somewhere since you still end up at index.pl.

    --
    I'm not belgian but I play one on TV. On dit que je parle comme un belge aussi.