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

Hi all
I am having a problem with HTML::Form I have a formbox that shows mulitple values ( "The Group A" "The Group B" "The Group C") I want to use HTML::Form to get the the name "The Group A" instead of the value foo. So if I use dumper to show what I'm talking about..
$VAR1 = bless( { 'id' => 'cmbDivision', 'name' => 'cmbDivision', 'menu' => [ { 'name' => 'The Group A', 'value' => '00' }, { 'name' => 'The Group B', 'value' => 'PQ' }, { 'seen' => 1, 'name' => 'The Group C', 'value' => 'HP' }, 'current' => 2, 'language' => 'javascript', 'onchange' => '__doPostBack(\'cmbDivision\',\'\')', 'type' => 'option'
So when I do this..
my $status_form = HTML::Form->parse($response); $proj{'status_division'}=$status_form->value('cmbDivision'); print"$proj{'status_division'}
It happily returns "HP" I want it to return "The Group C" Any ideas for the brain dead?? Thanks Much!!

Replies are listed 'Best First'.
Re: HTML::Form - Getting what is seen not the value..
by johnnywang (Priest) on Jan 22, 2005 at 07:38 UTC
    The following will give you a list of names:
    my $status_form = HTML::Form->parse($response); $status_form->find_input('cmbDivision', "option")->value_names();
      Hey this is close,

      For what ever reason this returns the number of entries not the value. I found this could be a bug actually cause it's supposed to work.

      http://article.gmane.org/gmane.comp.lang.perl.modules.lwp/1007 http://groups-beta.google.com/group/perl.beginners/browse_thread/thread/84e53f42f011521e/16f0bf1ce4925e0e?q=HTML::Form+value_names&_done=%2Fgroups%3Fq%3DHTML::Form+value_names%26hl%3Den%26lr%3D%26sa%3DN%26tab%3Dwg%26&_doneTitle=Back+to+Search&&d#16f0bf1ce4925e0e

      Any other ideas... TIA


      Rhodium

      The seeker of perl wisdom.

        It's a matter of context, in list context, it will return the full list, while in scalar context, it returns the number.
Re: HTML::Form - Getting what is seen not the value..
by davido (Cardinal) on Jan 22, 2005 at 06:31 UTC

    Are you looking for the param() method of HTML::Form? The POD for HTML::Form says this about the param() method:

    $form->param( $name, \@values )

    If called without arguments then it returns the names of all the inputs in the form. The names will not repeat even if multiple inputs have the same name. In scalar context the number of different names is returned.

    There is also an inputs() method, which in list context does just about the same thing, returning names.


    Dave

Re: HTML::Form - Getting what is seen not the value..
by holli (Abbot) on Jan 22, 2005 at 07:00 UTC
    i donīt know HTML::Form, but given the dump you provided, you can access the value you want this way:
    print $status_form->{menu}[-1]{name};
    Warning: playing with a modules internal data-structure can break upon itīs next version (if the structure changes).

    holli, regexed monk
Re: HTML::Form - Getting what is seen not the value..
by K_M_McMahon (Hermit) on Jan 22, 2005 at 04:54 UTC
    The code you have posted is not complete/syntax correct. Please update with corrections so it will run. Then myself/others can more easily check what is happening.

    -Kevin