rlb3 has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I’ve been experimenting with CGI::Prototype::Hidden and I’m having a few troubles. And frankly, this might be more of a CGI.pm problem but I’m not sure. I’ve been reading the docs and the code and I know I need to set a hidden _state param. In the docs the example is:

[% self.CGI.hidden(self.config_state_param) %]

This generates something like this:

<input type=”hidden” name=”_state” value=”Search”>

Btw, I overrode the default page to “Search”.

My problem is that I want the value to be “Display” so when I hit the submit button the app will move to the next page. So I tried this:

[% self.CGI.hidden(self.config_state_param,”Display”) %]

This gives a value of “Search” just like the first. If I hard code the hidden field it works as expected. What am I missing here?

My second problem is with self.CGI.end_form. When I tried:

[% self.CGI.end_form %]

I get an ARRAY reference and not the text. I looked at the code in CGI.pm and it looks like that the end_form function returns an array or a scalar depending on context. How do I force scalar context in the Template Toolkit?

Thanks to anyone who can help.

rlb3
  • Comment on Trying to understand how CGI::Prototype::Hidden, Template Toolkit and CGI.pm work together.
  • Select or Download Code

Replies are listed 'Best First'.
Re: Trying to understand how CGI::Prototype::Hidden, Template Toolkit and CGI.pm work together.
by merlyn (Sage) on Mar 09, 2005 at 20:11 UTC
    so when I hit the submit button the app will move to the next page
    The basic strategy there is that your submit button returns you to the same page, and in your "respond_per_page" method, you recognize the submit button and return the new page.

    The whole point of "state" is that the dispatcher can figure out what code should be used to respond to a given form. So it isn't a form in a user's browser that changes state, it's the respond controller that changes state.

    And yeah, that's a messy interaction between end_form and Template Toolkit. You have to add .join("") to the result of end_form. Feh. This will be clearer in the updated docs.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      Thanks, I was thinking I could use respond_per_page to move to a different page but I wasn't sure. And thanks for the tip on how to deal with end_form. I was using a foreach loop and it was looking very ugly. :)

        Since CGI.end_form really just spits out a single closed form tag, why not replace it with a literal </form>? This is what i have been doing when i use the CGI TT plugin.

        UPDATE: I really have no idea why. I am sure someone had good intentions ... but somehow painted themselves in a corner. Hind sight is 20/20 ... and from my recent work experience i have learned that some things can't be easily fixed.

        jeffa

        L-LL-L--L-LL-L--L-LL-L--
        -R--R-RR-R--R-RR-R--R-RR
        B--B--B--B--B--B--B--B--
        H---H---H---H---H---H---
        (the triplet paradiddle with high-hat)
        
      Ran into this today, and I'm using end_form.last to get the </form> tag to print (instead of an ARRAY reference). (The "last" functionality is something Template Toolkit provides for arrays). What's the point of CGI::end_form spitting out an array with two pointless '' tags anyway? Does anyone know the story behind it?