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

Hello, Can anyone suggest a way to post values to an array? I have a pl page with a form on it. I want to enter some information into the form and submit it. I then want the form to reappear but the previously posted information to appear below it. As the users post, the list below it is added.

I have been testing hidden elements in the form and trying to (de)reference the array between posts but I can't get it to work.

I would like to figure it out on my own so any pointers would be great

Replies are listed 'Best First'.
Re: Posting arrays
by moritz (Cardinal) on Mar 10, 2011 at 16:00 UTC

    Web forms are transmitted via HTTP, which supports only text and bytes, no arrays.

    So you need to convert your array to text, and then later turn the text into an array again.

    The simplest approach is to join the array by a delimiter that does not appear in the data, and split it again on the same delimiter.

Re: Posting arrays
by wind (Priest) on Mar 10, 2011 at 17:16 UTC

    If you want this to be a persistent list that all users can add to, then you need some type of database. You could even rely on something simple like a csv file and use Text::CSV.

    You won't be able to save state between users if you don't have some sort of database though. At most you'll be able to save each form submission from a particular user in an additional hidden variable, but all that data will only be visible to that single user and only until they close that browser.

    Note, if a single user solution is acceptable, you can also look into CGI::Session. And of course, I assume you're familiar with and using CGI.

    Finally, the following recent post was from a user asking about hidden fields CGI: retaining textarea contents in hidden field

      Thanks for the reply. Its actually only for the user session, so it will empty when the user moves away from the page.