Collecting Web Form Information Using a Loop

Mike Bonner bonnmike at gmail.com
Wed Sep 1 13:18:56 EDT 2010


Oh yeah, to do it the way you want, change yours to

       put $_POST[("Q" &  i)] &  comma after theSubmission

The way it was setup to begin with, you're trying to match a key with quotes
because you explicitly put quote & q etc in for evaluation. So in effect it
would return a non-existant array entry because its looking for the quotes.

However, the repeat for each is probably easier all around just because you
can set your script up to handle a changing number of post variables. Repeat
for each key will find however many are sent so that you can parse them and
don't have to mess with concatenating a string together. Also means you can
name them anything you want.  The only side affect of this is that since
arrays are unsorted, if you need results returned in a specific order based
on post variable name you'll need to sort them yourself.

IE:

put the keys of $_POST into tKeys
sort tKeys
repeat for each line theKey in tKeys
do your stuff here with $_POST[theKey]
end repeat
On Wed, Sep 1, 2010 at 11:06 AM, Phil Davis <revdev at pdslabs.net> wrote:

>  On 9/1/10 9:34 AM, Gregory Lypny wrote:
>
>> Hello everyone,
>>
>> On-rev question about collecting web form information.  Suppose I have a
>> questionnaire that uses 40 sequentially named menus for the answer choices.
>>  I could collect them individually like this.
>>
>>        put $_POST["Q1"] into q1
>>        put $_POST["Q2"] into q2
>>        put $_POST["Q3"] into q3
>>        put $_POST["Q4"] into q4
>>        put $_POST["Q5"] into q5
>>        ...
>>        put $_POST["Q40"] into q40
>>
>> But of course my first inclination is to avoid 40 lines and use a loop.
>>  So I tried
>>
>>        repeat with i=1 to 40
>>        put $_POST[(quote&  Q&  i&  quote)]&  comma after theSubmission
>>        end repeat
>>
>> and a number of variations, such as,
>>
>>        (quote&  Q&  the value of i&  quote)
>>
>> but all I ever get returned is an empty list, i.e., {,,,,,,,,,,,,}.  Any
>> suggestions?
>>
>
> Maybe break your one-liner into two:
>
>
> repeat with i = 1 to 40
>    put "Q" & i into tKey
>    put $_POST[tKey] & comma after theSubmission
> end repeat
>
> I would be surprised if this didn't work.
>
> Best -
> Phil Davis
>
>
>
>> Regards,
>>
>> Gregory
>> _______________________________________________
>> use-revolution mailing list
>> use-revolution at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-revolution
>>
>>
> --
> Phil Davis
>
> PDS Labs
> Professional Software Development
> http://pdslabs.net
>
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>



More information about the use-livecode mailing list