Re: Quickform - multiple rows

From: Date: Fri, 25 Mar 2005 18:11:51 +0000
Subject: Re: Quickform - multiple rows
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-18341@lists.php.net to get a copy of this message
On Fri, 25 Mar 2005 17:43:03 +0100, Andreas Blaafladt <andreas@blaafladt.no> wrote: > * 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. :-) > Of course this is possible....but you can't setDefauls correctly on them as they all have the same name. Also, the processing may not work right. It's much better to use an index. -- Justin Patrin

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