Re: dynamic array creation from form elements

From: Date: Fri, 16 Jan 2004 16:04:11 +0000
Subject: Re: dynamic array creation from form elements
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-174837@lists.php.net to get a copy of this message
nice one, solves my next problem as well if any elements are empty! Cheers, Jon jon bennett | jon@jben.net new media creative _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ J b e n . n e t 91 Gloucester Rd, Trowbridge, Wilts, BA14 0AD t: +44 (0) 1225 341039 w: http://www.jben.net/ On 16 Jan 2004, at 15:47, John W. Holmes wrote:
Jon Bennett wrote:
Hi, I've got a dynamically generated form and once it's submitted I need to _push the data from my form elements into an array so I can ad them to the db. My form elements are created like so: <?php $i = 1; while ($i <= $iListItems){ ?> <div class="row"> <div class="label">List Item <?php print $i ?>:</div><div class="formw"><input type="text" name="listItem<?php print $i ?>" size="40" /></div> </div>
Why don't you just skip the whole "$i" counter thing and name your input elements as "listItem[]" ? Name every one of them that; the same thing. Now when you submit your form, you'll already have an array, $_POST['listItem']. $_POST['listItem'][0] will be what was in the first one, $_POST['listItem'][1] in the second, etc. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#174837) next »