| Justin Patrin 2005-05-04, 8:57 pm |
| On 5/4/05, LJ Wilkinson <lj.wilkinson@comcast.net> wrote:
> Hi,
>=20
> I have a question about validation when grouping elements in an
> HTML_Quickform. Here's the situation:
>=20
> I have a quickform that has a subset of elements that are grouped using t=
he
> $form->addGroup() method. After the user submits the form, I have a
> function that iterates through the values in the $_POST array and uses th=
at
> information to construct either an update or insert statement that gets s=
ent
> to the db. This function, at present, requires that the values in the
> $_POST array are "flat", ie no nested arrays. When you leave out the nam=
e
> parameter to the addGroup function, it doesn't create nested arrays when
> filling out the $_POST array: it's flat, which makes me very happy.
>=20
> The problem arises when I try and validate one of the elements in a group=
..
> The normal addRule() method doesn't appear to work when you simply give i=
t
> the grouped element name as a parameter. The addGroupRule() function wor=
ks
> as advertised, but you need to pass it a group name, which means that I h=
ave
> to give my addGroup() calls a name, which means I no longer have flat $_P=
OST
> arrays. When I leave out the group name from the addGroupRule I get a we=
ird
> error about not finding HTML_QuickForm_Header::getElementName in
> QuickForm.php line 1051. I expect I'm not supposed to do that.
>=20
> I'd really rather not make my $_POST iterator function smarter to deal wi=
th
> nested arrays unless I have to. Does anyone have any suggestions as to h=
ow
> I can get the look and feel of element groups (an advcheckbox and a text
> element side-by-side), allow validation of one of those elements (the tex=
t
> element), and get a flat $_POST array?
>=20
I suggest setting the appendName parameter to false in addGroup().
$form->addGroup($els, 'name', 'label', 'seperator', false);
--=20
Justin Patrin
|