FormBuilder postGenerateForm + elementNamePrefix rules issue

From: Date: Thu, 11 May 2006 19:19:54 +0000
Subject: FormBuilder postGenerateForm + elementNamePrefix rules issue
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-24045@lists.php.net to get a copy of this message
Hi all, I have just started building an application using pear packages for the first time, and I have to complement you all on your hard work. The code is of high quality and the community seems very helpful. I have been working with DB_DataObject_FormBuilder [with DHTMLRules worked in] and while I've so far been able to find solutions to all of my problems in the documentation and archives, I am stumped on this one: The FormBuilder automatically adds rules for database fields that are not null -- a nice feature. I can change the default error string for these auto-generated rules -- also good. What I would like to do, however, is have custom error strings for each field, things like "you need a user name to log in," or, "your name is required to display on your profile." To do this, I tried putting rules like this in postGenerateForm()... $form->addRule('username',
                       'We need a name for you to log in with.',
                       'required',
                       null,
                       'client');
My problem is that I am using nested forms with elementNamePrefix set as per the instructions in the documentation... $personBuilder->elementNamePrefix = 'person'; ...so the above addRule returns an error because it cannot find 'personusername'. Also, experimenting without prefixes and looking at the $form after adding rules, I see that I am not replacing the old rules, but just pushing mine on top of the generated ones. I can see several hacks for fixing the issue, but I'm wondering if anyone has opinions on the best way to go about customizing required field messages. Thanks for your time, Paul Hinze

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