Webpage Segmentation repository


Granularity Items

Page data

Title Accessing and collecting post[] data from an array in PHP - The SitePoint Forums
Original URL http://community.sitepoint.com/t/accessing-and-collecting-post-data-from-an-array-in-php/96459 
Dataset URL 20140924153147 
Text Log In Articles Books Courses Welcome to The New SitePoint Forums. Some helpful posts to read. Where can I find the rules? Click the FAQ link in the top navigation bar. Where should I post? You'll find a document explaining all the categories and tags here. How do I [do something] in Discourse? Here is a handy Discourse Cheat Sheet. What are Trust Levels? Here is an explanation of Trust Levels. More help and feedback If you have feedback, questions or concerns, please post them in this feedback thread. If you would like to contact our Community Manager personally, feel free to send a private message or an email. PHP Accessing and collecting post[] data from an array in PHP 1 / 6 erabxesSitePoint Member 16d #1 I have a form like the one below which is posted to processForm.php, and the user can dynamically add more with jQuery. Please How can i access those arrays from subject[], grade[] and year[] inputs by the user? 1Reply created Sep 8 last post Sep 12 6 posts 204 views 3 users 2 2 2 tpuntSitePoint Enthusiast 16d #2 The square brackets in PHP denote an array, and so when you perform a var_dump() upon the $_POST array, you'll get something like the following (with dummy data): array(4) { ["subject"]=> array(3) { [0]=> string(1) "a" [1]=> string(2) "aa" [2]=> string(3) "aaa" } ["grade"]=> array(3) { [0]=> string(1) "b" [1]=> string(2) "bb" [2]=> string(3) "bbb" } ["year"]=> array(3) { [0]=> string(1) "c" [1]=> string(2) "cc" [2]=> string(3) "ccc" } ["submit"]=> string(6) "Submit" } This means you can access the subject, grade, and year arrays via $_POST['subject'], $_POST['grade'], and $_POST['year'] respectively. BlackScorp 14d #3 erabxes said: try to do something like tpuntSitePoint Enthusiast 14d #4 Using iteration to output the required input boxes would reduce OP's repetition. Though you need to switch your two square brackets around in order to get the same POST data format as in the original post. I'd also advise against quoting keys in HTML, because when dealing with this data in the $_POST array, you must also remember to put quotes onto the array keys (since it's part of their name): $_POST['\'subject\''] // or $_POST["'subject'"] That also reduces legibility and is just a pain in general to handle. BlackScorp 14d #5 agree with @tpunt but at least i would create a two dimensional array erabxesSitePoint Member 12d #6 Thanks to you guys , I got all i need! That's what I think! Log In to Reply Suggested Topics Topic Category Posts Views Activity Using checkbox To Delete A File PHP 8 28 Sep '03 Need help with Member Profiles PHP 9 4 May '12 Table not updating unless form is resent PHP 11 23 Nov '12 I need help in embedding my website with php code PHP 11 14 Sep '12 Auto filling form PHP 3 13 Nov '12 Want to read more? Browse other topics in PHP or view latest topics.
Words 566