Re: Quickform - submitting via javascript or submit button

From: Date: Fri, 31 Dec 2004 21:20:01 +0000
Subject: Re: Quickform - submitting via javascript or submit button
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-16542@lists.php.net to get a copy of this message
On Thu, 30 Dec 2004 08:19:51 +0100, Janus & Heidi <janusjr@tdcadsl.dk> wrote: > I have a form (http://googolplex.dk/pearform.php) where I am reloading > the form using 'onchange="javascript:this.form.submit();"' on a > checkbox, and then deciding whether certain elements should be activated: > > $form->addElement('advcheckbox', 'php', 'PHP', '', > 'onchange="javascript:this.form.submit();"', array('no', > 'yes')); > > if ($form->exportValue('php') == 'yes') > { > $form->addElement('text', 'php_version', 'PHP version'); > // etc... > } > > Of course, it would seem a bit silly to validate the form, if its > reloaded by 'form.submit()', so I tried to add the rules like this: > > if ($form->exportValue('send') == 'Godkend') > { > $form->addRule('aspnet_version', 'Indtast venligst ASP.NET versionen > - TEST', 'required'); > $form->addRule('php_version', 'Indtast venligst PHP versionen - > TEST', 'required'); > } > > (Note: My submit button is <input name="send" value="Godkend" > type="submit" />) > > Of course, this resultet in the form validating immediately when > reloaded by 'form.submit()', so I did this: > > if ($form->validate() && $form->exportValue('send') == > 'Godkend') Maybe try swapping these two? You could also set a special hidden form field with a special value before you use JS to submit the form. This would make it easier to know that the form was submitted by JS. > { > // Process > } > > But now the form won't process at all, could anyone tell me what I am > doing wrong ? > > Janus Roenne > > Ps. This is the first time I use Quickform :) > -- Justin Patrin

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