Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: passing an array to a checkbox_group

by khippy (Scribe)
on Oct 11, 2001 at 13:58 UTC ( #118183=note: print w/replies, xml ) Need Help??

in reply to passing an array to a checkbox_group

First, you don't create an array when putting data to a
$ variable, like you do to $str - It is a scalar, so
@array = ($str); does not work.

Instead, if possible use push to fill the array like this:
while (<>) { push @array, $str ; }


there are no silly questions


Replies are listed 'Best First'.
Re: Re: passing an array to a checkbox_group
by amulcahy (Acolyte) on Oct 11, 2001 at 14:57 UTC
    That worked, thanks. I have a follow-up question:
    In the 'multipart_form' I set a param 'TblMenu' to $STable, but when I call it from another Perl script it doesn't recognise it.
    $STable = 'tab001'; print $query->start_multipart_form("POST","printFields"); print $query->checkbox_group(-name=>'FieldNames', -value=>[ @array ]); $query->param( -name=>'TblMenu', -value=>$STable); print $query->submit('doWhat','Print Fields'); print $query->end_form;
    Calling Code:
    $SFields = join(", ",$query->param('FieldNames')); $STab = $query->param('TblMenu');
    $SFields returns the selected checkboxes
    $STab returns nothing.
    I feel like there should be something like
    $STab = $query->param('FieldNames.TblMenu');
    but I don't know what it is?

      Is it a tip to include a print statement at line 5 ?

      there are no silly questions

        I presume you mean this....
        print $query->param( -name=>'TblMenu', -value=>$STable);
        I tried that but it did not work?
      If I understand what you are asking, you seem to be wanting to set a variable in one script that outputs some html, and then access that variable's value the next time the form is submitted?

      If that's the case you need to be writing a hidden field into your first script's output that has the name and value you want to access in your second script. probably has a method for doing this.


      my tests seem to work ok, but I am unclear on how you are calling this from another script. do you mean as the action or some other means?

      Update: seems to work when I added this after line 7 in the first script.

      print $query->hidden('TblMenu');

      is this what you were wanting?

        OK - 'main' contains the form which calls 'second'

        use CGI; $query = new CGI; print $query->start_multipart_form("POST","second"); print $query->checkbox_group(-name=>'FieldNames', -value=>[ @array ]); $query->param( -name=>'Tbl1', -value=>'tabname'; print $query->submit('doWhat','Print Fields'); print $query->end_form;
        use CGI; $query = new CGI; $SFields = join(", ",$query->param('FieldNames')); $STab = $query->param('Tbl1');
        The result is:
        $SFields = Date, Forename, Middle, School
        $STab = Nothing?????

        that did it - thanks for your help, it was driving me batty.
      you have to pull the values from the checkbox with a param .. e.g.,
      and the resultant array is less tractable to splits and other parsing operations, so be prepared to use a substr() to separate out what you want.
Re: Re: passing an array to a checkbox_group
by AidanLee (Chaplain) on Oct 11, 2001 at 17:42 UTC

    Alternatively (depending on memory constraints), you can simply do:

    @array = <>;

    which puts one line in each array index. If you need that substr call, consider this:

    @array = <>; @array = map { substr($_,0,$x) } @array; #or in one step: @array = map { substr($_,0,$x) } <>;


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://118183]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2018-06-23 10:45 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.