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

Hi everyone.

I was hoping someone could help me find a way to dynamically add fields to a WWW::Mech form. It's easier to show than explan what I need to do.
my @cats = split(", ", $email_cat); $mech->submit_form( form_name =>'post', fields => { 'post_title' => '', 'post_category[]' => '' } );
post_category is a checkbox field with a name shared with lots of other checkboxes. They are all numerically named though, so there is a post_category[] checkbox with a value of 1, just like there is of 2 and 3. I need to create just the checkboxes for those listed in $cats in the above example. They are comma and space separated. Let's pretend..
my @cats = (1, 2, 5, 10, 44);
How do I make the number of post_category references dynamic to the size and values of my @cats? I hope this makes sense but

Replies are listed 'Best First'.
Re: Easiest way to dynamically add fields to mechanize
by Anonymous Monk on Mar 21, 2011 at 21:15 UTC
Re: Easiest way to dynamically add fields to mechanize
by ikegami (Patriarch) on Mar 21, 2011 at 21:41 UTC

    If you really must add inputs to a form,

    my $input = HTML::Form::Input->new(...); $input->add_to_form($form);
Re: Easiest way to dynamically add fields to mechanize
by Anonymous Monk on Mar 21, 2011 at 23:50 UTC
    What I mean is how do I make it fill in two post cat fields if the array has two elements or five fields if the array has five elements? I will never know ahead of time how many checkboxes will be checked