Forum Moderators: coopster

Message Too Old, No Replies

Creating an array from variables submitted by a form

         

AnonyMouse

9:32 pm on May 1, 2006 (gmt 0)

10+ Year Member



I have a form which consists of a load of tickboxes for required categories(amongst other things). I've arranged it so that each category tickbox has name="category_id_idnumber", where idnumber changes for each tickbox.

So, the form variables received might include (requestid=784, language=EN, category_id_3=Y, category_id_5=Y). I want to create an array of category ids from these form values, to send into a function.

How can I loop throught the submitted variable names, in order to create the required array, ONLY including those related to category_ids? (Or a bigger question - should I have set my form up in a different manner, in order to receive the data in a more useful form?!?)

Many thanks in advance to anyone who can decipher the above!

coopster

11:49 pm on May 1, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



If the form is of method post you would loop through the $_POST superglobal examining the keys returned to see if they match your *category* naming pattern.

hakre

10:17 am on May 2, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



or even use these specific form names as arrays. php supports that:

Variables from outside PHP [php.net]

see Example 12-11. More complex form variables

but coopster's hint on the $_POST[] array might be even of more practical use under specific circumstances.

--hakre