Re: Quickform - submitting via javascript or submit button
| From: | PitesaJ at peteramayer dot com | Date: | Wed, 19 Jan 2005 23:28:25 +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-17027@lists.php.net to get a copy of this message | ||
I was curious if you found a solution. I got it to work, probably better
solutions but it works. Let me know if there is a problem with this
method.
$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...
}
$g_buttons[] = & HTML_QuickForm::createElement('submit','btnSubmit',
'Submit');
// etc.
$form->addGroup($g_buttons, 'buttons', null, ' ', FALSE);
$form->addFormRule('_validate_whatever') ;
if ($_POST['btnSubmit']!=''){
if ($form->validate()) {
//etc..
}else {
$form->display();
}
}else {
$form->display();
}
_______________________________________________________________________________
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 :)
>