Re: Complex server-side rules with QuickForm

From: Date: Wed, 23 Mar 2005 18:05:33 +0000
Subject: Re: Complex server-side rules with QuickForm
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-18288@lists.php.net to get a copy of this message
On Tue, 22 Mar 2005 16:58:11 -0500, Joshua Beall <jbeall@heraldic.us> wrote: > Hi All, > > I am wanting to do "complex" server-side JS validation. I put "complex" in > quotes because complex is of course in the eye of the beholder. Ok, first thing. "server-side" and "JS" are mutually exclisuve. Server-side rules are PHP and client-side rules are JS. > > What I would like to do is actually fairly simple in theory. We have a drop > down box, and a text box. We ask the user for their favorite color, and the > options in the drop down box are red, green, blue, or other. If they choose > red, green, or blue, then the text box is grayed out (disabled='disabled' > attribute is set for the <input> tag). If they choose other, then the text > box becomes available for them to input their favorite color in. > > Is there a way to do this with QuickForm without resorting to hand-coding > all the JS? I have a vague sense that I once saw a tutorial on how to do > this, but I've been googling for it and not been able to turn anything up. > I would be very grateful for any tips! > Sounds more like you want some DHTML, not validation. You can easily add an onChange for the select box using: $el->updateAttributes('onchange' => 'someJSFunction(this)'); If you want to validate that as well, the easiest way is with a formRule, which would be server-side only. function validateSomething($values) { //return true or array with error message(s) } $form->addFormRule('validateSomething'); If you want to add custom JS validation I think you need to create a new rule type (class), register it, and add it to your form. -- Justin Patrin

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