Prev: [ANNOUNCEMENT] Net_Whois-1.0.2 (stable) Released.
Next: [ANNOUNCEMENT] Mail_Mbox-0.6.2 (beta) Released.
From: Alain Williams on 7 Nov 2009 18:58 Hi, I have a form in which there is an Email and a Phone field. I want to ensure that I have at least one of these set, I also want to apply some validation to the 2 fields. Even if both fields are filled in it complains about not enough. Can someone please tell me where I am going wrong. BTW: I am using HTML/QuickForm.php on PHP5 (I have had to patch lots of things to get rid of the warnings) $contact[] = $form->addElement('text', 'Email', 'Email', 'size=50'); $form->addRule('Email', 'Invalid email address', 'email', null, 'client'); $contact[] = $form->addElement('text', 'Phone', 'Phone', 'size=20'); $form->addRule('Phone', 'Invalid phone number', 'regex', '/^[0+][\d ]+$/', 'client'); $form->addGroup($contact, 'contact'); $form->addGroupRule('contact', 'You must enter at least one of Phone number or Email address', 'required', null, 1, 'client'); -- Alain Williams Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php Past chairman of UKUUG: http://www.ukuug.org/ #include <std_disclaimer.h>
From: Alexey Borzov on 8 Nov 2009 03:51 Hi Alain, Alain Williams wrote: > I have a form in which there is an Email and a Phone field. > I want to ensure that I have at least one of these set, I also want > to apply some validation to the 2 fields. > > Even if both fields are filled in it complains about not enough. > > Can someone please tell me where I am going wrong. > > BTW: I am using HTML/QuickForm.php on PHP5 (I have had to patch lots of things > to get rid of the warnings) Sure you haven't broken anything? > $contact[] = $form->addElement('text', 'Email', 'Email', 'size=50'); Here you should have used createElement() > $form->addRule('Email', 'Invalid email address', 'email', null, 'client'); That should be done via addGroupRule() after adding the group. > $contact[] = $form->addElement('text', 'Phone', 'Phone', 'size=20'); > $form->addRule('Phone', 'Invalid phone number', 'regex', '/^[0+][\d ]+$/', 'client'); > $form->addGroup($contact, 'contact'); > $form->addGroupRule('contact', 'You must enter at least one of Phone number or Email address', 'required', null, 1, 'client'); Basically you've added a couple of fields to a form via addElement() and then added the same fields to a group *again*. I'm not sure that HTML_QuickForm is smart enough to detect and handle that. Consider using HTML_QuickForm2 instead, especially if you want to get rid of E_STRICT error messages. It *will* detect such things and won't add one element to two containers, it also attaches Rules to elements rather than to a form so it's a bit more intuitive and throws Exceptions in case of programming errors: these are a bit more difficult to ignore than PEAR_Errors.
From: Alain Williams on 8 Nov 2009 05:55 On Sun, Nov 08, 2009 at 11:51:47AM +0300, Alexey Borzov wrote: > >BTW: I am using HTML/QuickForm.php on PHP5 (I have had to patch lots of > >things > >to get rid of the warnings) > > Sure you haven't broken anything? I don't think so, but .... > That should be done via addGroupRule() after adding the group. Thanks > Basically you've added a couple of fields to a form via addElement() and > then added the same fields to a group *again*. I'm not sure that > HTML_QuickForm is smart enough to detect and handle that. I think that I have tried that, I'll try again. > Consider using HTML_QuickForm2 instead, especially if you want to get rid > of E_STRICT error messages. It *will* detect such things and won't add one I am using smarty - I can't see the smarty renderer. It might be simpler to port that to PHP5 & QF2. Also I am running on CentOS - which has php-5.1.6, quickform2 needs php > 5.2. I would have liked to use HTML_QuickForm2. Regards -- Alain Williams Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php Past chairman of UKUUG: http://www.ukuug.org/ #include <std_disclaimer.h>
From: Alexey Borzov on 8 Nov 2009 06:40 Hi Alain, Alain Williams wrote: >> Consider using HTML_QuickForm2 instead, especially if you want to get rid >> of E_STRICT error messages. It *will* detect such things and won't add one > > I am using smarty - I can't see the smarty renderer. It might be simpler to > port that to PHP5 & QF2. There is an Array renderer that can be used with Smarty, but there isn't yet (?) a port of ArraySmarty one. BTW, if someone wants to port that to QuickForm2, he is most welcome to do so, it can be added to PEAR as a separate subpackage. Neither Bertrand nor myself are using Smarty, so obviously ArraySmarty is at the bottom of our priority list. > Also I am running on CentOS - which has php-5.1.6, quickform2 needs php > 5.2. > I would have liked to use HTML_QuickForm2. Note that QuickForm2 requires PHP 5.2 due to a major problem in PHP 5.1.x: http://pear.php.net/bugs/bug.php?id=14110 http://bugs.php.net/bug.php?id=37632 Also note that 5.1.6 is 3+ years old: http://www.php.net/ChangeLog-5.php#5.1.6 It may be possible to run QuickForm2 under 5.1.6, but that'll require declaring most of the methods in subclasses of HTML_QuickForm2_Node as public. In short, it would be a good idea to update your PHP installation (I'm not familiar with CentOS, but usually there is some kind of backports repository for Linux distributions, or you can build a custom binary package from a source one).
From: Alain Williams on 8 Nov 2009 09:17 On Sun, Nov 08, 2009 at 02:40:11PM +0300, Alexey Borzov wrote: > BTW, if someone wants to port that to QuickForm2, he is most welcome to do > so, it can be added to PEAR as a separate subpackage. Neither Bertrand nor > myself are using Smarty, so obviously ArraySmarty is at the bottom of our > priority list. I'll do that iff I can get QF2 going. > >Also I am running on CentOS - which has php-5.1.6, quickform2 needs php > > >5.2. > >I would have liked to use HTML_QuickForm2. > > Note that QuickForm2 requires PHP 5.2 due to a major problem in PHP 5.1.x: > http://pear.php.net/bugs/bug.php?id=14110 > http://bugs.php.net/bug.php?id=37632 Drat! It has not been patched. > Also note that 5.1.6 is 3+ years old: > http://www.php.net/ChangeLog-5.php#5.1.6 > > It may be possible to run QuickForm2 under 5.1.6, but that'll require > declaring most of the methods in subclasses of HTML_QuickForm2_Node as > public. > > In short, it would be a good idea to update your PHP installation (I'm not > familiar with CentOS, but usually there is some kind of backports > repository for Linux distributions, or you can build a custom binary > package from a source one). CentOS is a free version RedHat Enterprise -- essentially just the Logos replaced. I am running CentOS 5.4 (the latest out). Version 5.0 was released in March 2007, they stick to the same version of things throughout releases. Version 6 is rumoured to be out in Q1 next year. I can't find someone who is offering php 5.2 (or 5.3) for this platform. I have downloaded the Fedora 12 (out soon) RPM, that is php 5.3.0, this is what will presumably be used in RedHat Enterprise 6 next year. I'll try to get this compiled up for CentOS/RHE 5.4. -- Alain Williams Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php Past chairman of UKUUG: http://www.ukuug.org/ #include <std_disclaimer.h>
|
Next
|
Last
Pages: 1 2 3 Prev: [ANNOUNCEMENT] Net_Whois-1.0.2 (stable) Released. Next: [ANNOUNCEMENT] Mail_Mbox-0.6.2 (beta) Released. |