Re: Quickform - multiple rows

From: Date: Fri, 25 Mar 2005 16:43:03 +0000
Subject: Re: Quickform - multiple rows
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-18340@lists.php.net to get a copy of this message
* Obsessed <Obsessed@dayofdefeat.be> [2005-03-25 10:52:28]: > I'm trying to create a list with usernames and emails. > The email field is a textfield that is editable, so the admin can change > the emailaddres. on each row we have a label, textfield with email and a > (submit) button. > Now I'm trying to get all the correct emails from the database and into > the textfields. Now here is the problem, I keep getting the same email > (from the last user in array) in all my textfields. > Here is some code the array users contains other arrays with username > and email in them > > > $users = db_GetUsers(); > > $formusers = new HTML_QuickForm('frmEditUser', 'post'); > $formusers->addElement('header', 'UserHeader', > 'Overzicht > Medewerkers'); > > foreach($users as $user) > { > $formusers->addElement('text', 'email', > $user['username']); > $formusers->addElement('submit', btnEdit', > 'Wijzig'); > $formusers->addElement('submit', 'btnDelete', > 'Verwijderen'); > $formusers->setDefaults($user); > } > > > thx > First off, I'm by no means a QuickForm expert. You're adding elements with the same names over and over again (email, btnEdit, btnDelete) in the same HTML_QuickForm instance, and even though every addElement()-operation results in a new row, it is practically speaking the same element. And hence, the last setDefaults() sets the values of the field(s). On a slightly related note, last time I did something similar in php, I added fields suffixed by []'s. Eg: <input type="text" name="user[]" value="Joe" /> With this, I could access the the values using $_POST['user'][index], where index would be a number from 0 to n-1 numbers of input-fields. However, this approach doesn't seem to be possible in QuickForm. Hopefully, someone with more QuickForm-experience will say a few words about this. :-) /Andreas -- andreas blaafladt <andreas@blaafladt.no>

« previous php.pear.general (#18340) next »