|
-
Jun 30th, 2009, 12:33 PM
#1
Thread Starter
Lively Member
posting an array on submit
I have an array that I need to submit to a form. An array does not fit into any of the known form elements. How can I fit this array into scheme of forms and submit it?
Save trees, avoid plastics, say no to zoo, go veg, recycle as much, live holistic
-
Jun 30th, 2009, 03:13 PM
#2
Re: posting an array on submit
arrays on forms work like this (if submitted via post, otherwise use $_GET):
PHP Code:
//the following produces the variable $_POST['array']['key'] with a value of "test" <input type="hidden" name="array[key]" value="test" />
//the following produces the variable $_POST['array'][0] through $_POST['array'][2] with a value of "test" <input type="hidden" name="array[]" value="test" /> <input type="hidden" name="array[]" value="test" /> <input type="hidden" name="array[]" value="test" />
so, if you have your array, you can simply loop through it using a foreach(), and then put it into hidden elements.
PHP Code:
<?php foreach($myarray as $key => $value): ?> <input type="hidden" name="myarray[<?php echo $key; ?>]" value="<?php echo htmlentities($value); ?>" /> <?php endforeach; ?>
the above code would produce an array that could be accessed via the same keys as the original array, but the "root" array would be $_POST['myarray'] rather than $myarray. for simplicity's sake, you could redefine it to use $myarray after you had submitted the form.
hope that was what you were looking for!
-
Jul 1st, 2009, 03:01 AM
#3
Thread Starter
Lively Member
Re: posting an array on submit
Yes, this is what I was looking for. Thanks!
Save trees, avoid plastics, say no to zoo, go veg, recycle as much, live holistic
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|