Re: FormBuilder postGenerateForm + elementNamePrefix rules issue
| From: | Justin Patrin | Date: | Thu, 11 May 2006 19:59:38 +0000 |
| Subject: | Re: FormBuilder postGenerateForm + elementNamePrefix rules issue | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-24046@lists.php.net to get a copy of this message | ||
On 5/11/06, Paul Hinze <paul.t.hinze@gmail.com> wrote:
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.
Yep. This is one of the quirks having to do with the prefix/postfix
options. Use $fb->getFieldName('username') instead of 'username'.
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.As for replacing the messages...I'm not quite sure. It *could* be possible to add support to FB for element specific messages or perhaps there's a way to remove the rule with QF. -- Justin Patrin