in reply to CGI: which field has changed?

If you cannot use JS, then you will have to regenerate the page every time a change in one the menus is made by the user.

The http-protocol being essentially stateless, means that you will have to jump through a lot of hoops to "remember" what the previous state of the page was. Session-management springs to mind in that respect, but you can also keep the previous values of the menu-choices in some hidden fields.

Using hidden fields, it is easy to check which choices have changed and regenerate the page.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re^2: CGI: which field has changed?
by davies (Monsignor) on Feb 26, 2011 at 17:30 UTC

    Yes, I was expecting to have to regenerate, but since there are only four fields plus two or three buttons, I wasn't overly concerned. I read about hidden fields in the CGI docs, but couldn't envisage an application. Thanks to you, I can now! :-)

    Regards,

    John Davies

      This actually proved harder than I thought. Partly it was because I did something stupid (CGI: retaining textarea contents in hidden field), but even with this fixed, things didn't work as I expected. My code is now working as I want, but I have the following two lines in my code:

      print hidden(-name => "Old" . $param , -value => $value); param( -name => "Old" . $param , -value => $value);

      I can't find any documentation that indicates that the second line should be needed, but if I leave it out, the values don't get saved. I therefore report this in case anyone else runs into the same problem. Of course, if this should need only one line and I'm doing something else daft, I'd love to know.

      Regards,

      John Davies

        I'm guessing you're missing
        http://search.cpan.org/dist/CGI.pm/lib/CGI.pm#FORM_ELEMENTS
        -override
        A boolean, which, if true, forces the element to take on the value specified by -value, overriding the sticky behavior described earlier for the -nosticky pragma.
        print hidden(-name => "Old" . $param , -value => $value, -override => 1);