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

I'm sure this is a newbie question that you can answer in your sleep but,

Using an HTML online form, I would like to control which fields are displayed to the user upon display of the success_page.

I think the code that needs tweaking is:

-------------------------------------

=item success_page_fields () Outputs success page HTML output for each input field. =cut sub success_page_fields { my ($self) = @_; foreach my $f (@{ $self->{Field_Order} }) { my $val = (defined $self->{Form}{$f} ? $self->{Form}{$f} : ''); $self->success_page_field( $self->escape_html($f), $self->escape_h +tml($val) ); } }

-------------------------------------

Any help would be GREATLY appreciated!

Janitored by Arunbear - added code tags and retitled from 'success_page_fields'

  • Comment on How to display only certain fields during dynamic HTML generation?
  • Download Code

Replies are listed 'Best First'.
Re: How to display only certain fields during dynamic HTML generation?
by Arunbear (Prior) on Oct 22, 2004 at 20:26 UTC
    First choose the fields you are interested in:
    my %fields_to_show = map { $_ => 1 } qw/field1 field2 field3/;
    now modify your loop to skip fields you don't want:
    foreach my $f (@{ $self->{Field_Order} }) { next unless exists $fields_to_show{$f}; my $val = (defined $self->{Form}{$f} ? $self->{Form}{$f} : ''); $self->success_page_field( $self->escape_html($f), $self->escape_html($val) ); }
Re: How to display only certain fields during dynamic HTML generation?
by TedPride (Priest) on Oct 22, 2004 at 17:19 UTC
    I could be wrong, but it looks like you can edit the list of fields to display by changing $self->{Field_Order}. For instance, if you're calling success_page_fields() as follows:
    success_page_fields($hashp);
    You can edit the list of fields with the following:
    $hashp->{'Field_Order'} = ['field1', 'field2', 'etc']; success_page_fields($hashp);
Re: How to display only certain fields during dynamic HTML generation?
by dws (Chancellor) on Oct 23, 2004 at 05:10 UTC

    I would like to control which fields are displayed to the user upon display of the success_page.

    This is a problem that templates are ideally suited to handle. Using HTML::Template, for example, a template to handle static {name, value} pairs might look something like

    <TMPL_IF foo>foo: <TMPL_VAR foo ESCAPE=HTML><br /></TMPL_IF>

    It's only slightly more complicated to handle dynamic {name, value} pairs.

    <TMPL_LOOP vars> <TMPL_IF value><TMPL_VAR name ESCAPE=HTML>: <TMPL_VAR value ESCAPE=HTML><br /></TMPL_VAR> </TMPL_LOOP>

    A Super Search for "HTML::Template" will turn up lots of examples to show how to set this up in code.