Re: QuickForm - several questions
| From: | Bertrand Mansion | Date: | Wed, 02 Jul 2008 11:04:32 +0000 |
| Subject: | Re: QuickForm - several questions | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-29061@lists.php.net to get a copy of this message | ||
Le 2 juil. 08 à 00:14, Frank Bax a écrit :
I've got my first form done in 1.5 days (uses groups, text, textarea, radio, advcheckbox, files) with results being emailed using Mail & Mail_Mime. It works; but there are some things I'd still like to change a little bit. 0) Thanks to helpers on #pear irc channel for directing me to advcheckbox instead of checkbox! 1) Labels for text elements ('First', 'Middle', 'Last') in a group do not appear on the form (this works for grouped radio, checkbox). $name[] = &HTML_QuickForm::createElement('text', 'First', 'First', array('size'=>20,'maxlength'=>30)); $name[] = &HTML_QuickForm::createElement('text', 'Middle', 'Middle', array('size'=>10,'maxlength'=>30)); $name[] = &HTML_QuickForm::createElement('text', 'Last', 'Last', array('size'=>20,'maxlength'=>30)); $form->addGroup($name, 'Names', 'Name of Applicant: ', '<br>');This problem is related to the use of templates with QuickForm. Basically, you have to provide the renderer with a template that prints these labels. The default one for groups doesn't I think. Look at the renderer you use, especially the following method: http://pear.php.net/manual/en/package.html.html-quickform.html-quickform-renderer-default.setgroupelementtemplate.php
2) With above first,middle,last name; how do I create a rule to make first/last required; but middle optional? Using addRule on elements seems to be ignored; using addGroupRule seems to make all three elements required. $form->addGroupRule('Names', 'Applicant\'s name is required', 'required'); $form->addRule('First', 'Applicant\'s first name is required', 'required'); $form->addRule('Last', 'Applicant\'s last name is required', 'required');Have a look at either : http://pear.php.net/manual/en/package.html.html-quickform.html-quickform.addgrouprule.php http://pear.php.net/manual/en/package.html.html-quickform.html-quickform.addformrule.php
3) If I combine yes/no radio elements and a text field into a group. Is it possible to require the text field be entered whenever the 'Yes' radio was selected? $coll[] = &HTML_QuickForm::createElement('radio', null, null, 'Yes', 'College_Yes'); $coll[] = &HTML_QuickForm::createElement('radio', null, null, 'No', 'College_No'); $coll[] = &HTML_QuickForm::createElement('text', 'Diploma:', null, array('size'=>25), 'Program:'); $form->addGroup($coll, 'College', 'College Diploma: ', '<br>');This is more complex, so use: http://pear.php.net/manual/en/package.html.html-quickform.html-quickform.addformrule.php
4) If user enters files to be uploaded; but server finds validation errors; the filename disappears and must be reloaded. Is there a way to avoid this behaviour.No, that's the browser's fault, nothing can be done about it unless you develop a solution yourself (ex: temporarily store the file, even if the form validation fails)
5) If I specify client-side required rule for radio and/or checkbox; it is only checked on server side. $form->addGroupRule('FullG', 'A yes/no answer is required', 'required', '', 'client');Use addRule() instead.
6) After calling $form->freeze(); 'file', 'submit' and 'reset' elements are not frozen?That's the expected behavior. If you don't want it like that, you shouldn't use freeze(). Freeze() is a way to present a frozen form for the user to review what she submitted. -- Bertrand Mansion Mamasam Work : http://www.mamasam.com Blog : http://golgote.freeflux.net