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

CGI/OpenThought array/hash handling

by ksublondie (Pilgrim)
on Dec 30, 2010 at 20:54 UTC ( #879866=perlquestion: print w/ replies, xml ) Need Help??
ksublondie has asked for the wisdom of the Perl Monks concerning the following question:

Here's what I'm working on: I have CGI interface using OpenThought to display a list of properties and their associated owners along with their ownership share in the property. Of course each property can have a variable amount of owners. Each owner listed has a dynamic input for editing their share value. I'm struggling on how to pass the share parameter as an array through OpenThought. According to CGI documentation, I should be able to retrieve the parameter array at the server with @shares = $query->param('share');, but all I get when calling scalar @shares is 1.

I've determined that the parameters are using the name tag property instead of id. Since I'm using dynamic inputs and am using javascript to caculate the share totals, I'd like to implement the array design...nice and clean. I could just name them uniquely and use some sort of regex to create the array at the server, but then I'd have to redesign the share calculations and retrieving the values at the server would get dirty.

I haven't found any real-life examples of using arrays, jsut the arrays in the documentation...which I can't get to work. I would LOVE to use hashes...but I haven't seen any reference to it. Does anyone have any ideas for me?

#server code sub editShares_save{ my $self = shift; my $q = $self->query; my $OT = OpenThought->new(); my $params; my @names=$q->param; my @Share=$q->param('Share'); warn (scalar @Share)."\n"; foreach(@names){warn 'name='.($_).' value='.($q->param("$_"))."\n";} } #generated HTML form <table class="tablecontent1"> <tr align='right'> <td></td> <td>Share</td><td></td> </tr><tr> <td> - John Smith </td> <td><input type="text" onkeyup="updateShares()" onblur="formatShar +es(this);updateShares()" name="Share" id="ShareD43C272F-FDEA-0D6C-D3E +0-68357BAB6197" value="0.00"></td> <td>% </td> </tr><tr> <td> - Jane Doe </td> <td><input type="text" onkeyup="updateShares()" onblur="formatShar +es(this);updateShares()" name="Share" id="Share2C0C4234-17D2-CFBC-E39 +3-03FDBE78F6F2" value="0.00"></td> <td>% </td> </tr> </table> <input type='button' value='Save' onclick='save();'> <script> function save(){ var answer=confirm('Are you sure you want to modify this ?'); if(answer){ document.getElementById("save").value=1; showWait(1); var data=["id","save","Share*"]; OpenThought.CallUrl(url, data); } } </script>

Comment on CGI/OpenThought array/hash handling
Select or Download Code
Re: CGI/OpenThought array/hash handling
by Khen1950fx (Canon) on Dec 31, 2010 at 06:41 UTC
    Your question isn't clear to me, so this isn't an answer but an example of the way that I tried it. Based on the documentation's use of a hash:
    #!/usr/bin/perl use strict; use warnings; use OpenThought(); use CGI(); my $OT = OpenThought->new(); my $q = CGI->new; my $html; my %fields; $fields{'List'} = [ [ "John Smith", "50" ], [ "Jane Doe", "50" ], ]; $html->{'id_tagname'} = "<b>html</b>"; my $js = "Does this help?"; $OT->param( \%fields ); $OT->param($html); $OT->focus("Share"); $OT->javascript($js); print $q->header; print $OT->response();
Re: CGI/OpenThought array/hash handling
by ksublondie (Pilgrim) on Dec 31, 2010 at 16:02 UTC
    I suppose I should clarify: I'm trying to retrieve the share values as an array from the submitted HTML, not output the values.
      Where?
        At the following line:
        OpenThought.CallUrl(url, data);
        "url" is the url that calls the server function editShares_save(). I'm able to retrieve all my other variables just fine, but not the share variable as an array.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2014-09-23 22:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (241 votes), past polls