Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

killerhippy


Comment on Re: passing an array to a checkbox_group
Download Code
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?

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

      there are no silly questions

      killerhippy
        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. CGI.pm probably has a method for doing this.

      Guy

      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'

        main:
        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;
        second:
        use CGI; $query = new CGI; $SFields = join(", ",$query->param('FieldNames')); $STab = $query->param('Tbl1');
        The result is:
        $SFields = Date, Forename, Middle, School
        $STab = Nothing?????

        AM
        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.,
      @fieldnames=$query->param('FieldNames')
      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) } <>;

    HTH

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://118183]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2014-07-14 04:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (254 votes), past polls