|
View:
New views
14 Messages
—
Rating Filter:
Alert me
|
|
|
Quickform group rulesHi,
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> -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Quickform group rulesHi 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. -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Quickform group rulesOn 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> -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Quickform group rulesHi 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). -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Quickform group rulesOn 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> -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Quickform group rules> 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. PHP 5.2 is in the c5-testing repo, you just have to enable that in your /etc/yum.repos.d files. PHP 5.3 for CentOS is here: http://rpms.famillecollet.com/el5.i386/ -- Del Babel Com Australia http://www.babel.com.au/ ph: 02 9966 9476 fax: 02 9906 2864 -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
|
|
|
Re: Quickform group rulesOn Sun, Nov 08, 2009 at 02:40:11PM +0300, Alexey Borzov wrote:
> 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. OK: I ported php 5.3 to CentOS and am puzzling on how to use QF2 with the array renderer. I looked at the ArrayTest.php - and have got something out of it that I could start to pick to bits, but that is just by seeing what is in there and guessing -- not by *knowing* what should be in there and using it. It is there any decent documentation about this ? It is something that I find really frustrating about PEAR - lots if nice stuff but little real doumentation -- the phpDocumentor stuff just is not useful when you are starting out trying to understand what the heck is going on. Ideally the documentation should be written by the authors since they know what the *intention* of everything is. I have found this: http://quickform.mamasam.com/wiki/doku.php but it still doesn't really fit the bill. 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> -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Quickform group rulesHi 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. > > OK: I ported php 5.3 to CentOS and am puzzling on how to use QF2 with the > array renderer. I looked at the ArrayTest.php - and have got something out of > it that I could start to pick to bits, but that is just by seeing what > is in there and guessing -- not by *knowing* what should be in there and > using it. > > It is there any decent documentation about this ? Not yet, it's 0.3.0-alpha for a reason, you know... As for Array renderer, this is the direct port of Array renderer from QuickForm 3.x, so you can review the examples, docs and templates for that: http://pear.php.net/manual/en/package.html.html-quickform.html-quickform-renderer-array.php http://svn.php.net/viewvc/pear/packages/HTML_QuickForm/trunk/docs/renderers/templates/smarty-dynamic.tpl?revision=165897&view=markup http://svn.php.net/viewvc/pear/packages/HTML_QuickForm/trunk/docs/renderers/SmartyDynamic_example.php?revision=236645&view=markup The resultant array structure is a bit different, of course, since QuickForm2 uses fieldsets rather than headers and allows unlimited Container nesting. BTW, I'm not familiar with current Smarty, but if it understands Iterators and can call (and chain) object methods, then maybe no renderer is needed at all. E.g.: {$form->getElementById('myElement')->__toString()} or: {foreach from=$form item=element} {$element->getLabel()} {$element->__toString()} {/foreach} > Ideally the documentation should be written by the authors since they know > what the *intention* of everything is. This is a good excuse for not helping to write docs, I'll use it from this time on. :] > I have found this: > http://quickform.mamasam.com/wiki/doku.php > but it still doesn't really fit the bill. That's mostly for planning and discussing implementation, yes. But we won't object if someone starts sketching docs there. -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Quickform group rulesOn Fri, Nov 13, 2009 at 06:42:47PM +0300, Alexey Borzov wrote:
> Not yet, it's 0.3.0-alpha for a reason, you know... Yes & I know that producing the documentation takes as long as writing the code, I have done enough of that with some stuff that I have released GPL recently. > As for Array renderer, this is the direct port of Array renderer from > QuickForm 3.x, so you can review the examples, docs and templates for that: > http://pear.php.net/manual/en/package.html.html-quickform.html-quickform-renderer-array.php > http://svn.php.net/viewvc/pear/packages/HTML_QuickForm/trunk/docs/renderers/templates/smarty-dynamic.tpl?revision=165897&view=markup > http://svn.php.net/viewvc/pear/packages/HTML_QuickForm/trunk/docs/renderers/SmartyDynamic_example.php?revision=236645&view=markup > > The resultant array structure is a bit different, of course, since > QuickForm2 uses fieldsets rather than headers and allows unlimited > Container nesting. > > BTW, I'm not familiar with current Smarty, but if it understands Iterators > and can call (and chain) object methods, then maybe no renderer is needed > at all. I am writing an renderer for Smarty - I have taken the array renderer and am modifying/butchering/... it. I am aiming to product an array (which is what Smarty wants) that is compatible with current Smarty templates -- ie you are going to need to change the PHP, but hopefully will not have to change the templates. I will, of course, release it back to this list when it works: for comment/correction and, hopefully, inclusion into the main distribution. Yes: I will document it, probably something along the lines, and expanded, of my site which is the number 1 hit when I google ''smarty quickform example''. > E.g.: > {$form->getElementById('myElement')->__toString()} > > or: > {foreach from=$form item=element} > {$element->getLabel()} > {$element->__toString()} > {/foreach} That may be posssible -- although I am trying to avoid changes to *existing* smarty templates. -- 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> -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Quickform group rulesOn Fri, Nov 13, 2009 at 04:09:33PM +0000, Alain Williams wrote:
> I am writing an renderer for Smarty - I have taken the array renderer and am modifying/butchering/... it. > I am aiming to product an array (which is what Smarty wants) that is compatible with current > Smarty templates -- ie you are going to need to change the PHP, but hopefully will > not have to change the templates. Please find attached some new files that implement the above: a smarty renderer for QuickForm2 * Renderer.php Modified to know about the smarty renderer. Accept a new option 'old_compat' - this causes the smarty renderer to do somethings that might not be wanted if you were starting from new. The point is that it allows existing smarty templates to be used without change. * Smarty.php This implements a renderer. It works - at least in the way that I use QuickForm. There are some things not implemented, I prob did not understand how to do it with QuickForm. There are some comments saying what the returned array contains. This was developed under PHP 5.3 on Linux. To see how this plugs together see a tutorial set that I have at: http://www.phcomp.co.uk/TechTutorial/QfSmarty/index.php (This runs the QuickForm and NOT the QuickForm2 version, but the output is the same). All feedback gratefully accepted. This is cross posted to both the PEAR-GENERAL and the SMARTY-DEV mail lists since it is relevant to both. Have fun! -- 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> -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Smarty QuickForm2 RendererTry again - this time with a proper Subject and with the
renderer attached. On Fri, Nov 13, 2009 at 04:09:33PM +0000, Alain Williams wrote: > I am writing an renderer for Smarty - I have taken the array renderer and am modifying/butchering/... it. > I am aiming to product an array (which is what Smarty wants) that is compatible with current > Smarty templates -- ie you are going to need to change the PHP, but hopefully will > not have to change the templates. Please find attached some new files that implement the above: a Smarty renderer for QuickForm2 * Renderer.php Modified to know about the smarty renderer. Accept a new option 'old_compat' - this causes the smarty renderer to do somethings that might not be wanted if you were starting from new. The point is that it allows existing smarty templates to be used without change. * Smarty.php This implements a renderer. It works - at least in the way that I use QuickForm. There are some things not implemented, I prob did not understand how to do it with QuickForm. There are some comments saying what the returned array contains. This was developed under PHP 5.3 on Linux. To see how this plugs together see a tutorial set that I have at: http://www.phcomp.co.uk/TechTutorial/QfSmarty/index.php (This runs the QuickForm and NOT the QuickForm2 version, but the output is the same). All feedback gratefully accepted. This is cross posted to both the PEAR-GENERAL and the SMARTY-DEV mail lists since it is relevant to both. Have fun! -- 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> -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Smarty QuickForm2 RendererHi Alain,
Alain Williams wrote: > Try again - this time with a proper Subject and with the > renderer attached. You are using the smarty-dev list that is defunct for quite a bit of time: http://news.php.net/php.smarty.dev/3071 > On Fri, Nov 13, 2009 at 04:09:33PM +0000, Alain Williams wrote: > >> I am writing an renderer for Smarty - I have taken the array renderer and am modifying/butchering/... it. >> I am aiming to product an array (which is what Smarty wants) that is compatible with current >> Smarty templates -- ie you are going to need to change the PHP, but hopefully will >> not have to change the templates. > > Please find attached some new files that implement the above: a Smarty renderer for QuickForm2 > > * Renderer.php > Modified to know about the smarty renderer. > Accept a new option 'old_compat' - this causes the smarty renderer to do somethings > that might not be wanted if you were starting from new. The point is that it allows > existing smarty templates to be used without change. You could add this option in your Renderer's constructor, no need to patch the base class. > * Smarty.php > This implements a renderer. It works - at least in the way that I use QuickForm. > There are some things not implemented, I prob did not understand how to do it > with QuickForm. > There are some comments saying what the returned array contains. I had a brief look at your implementation: 1) Why aren't you extending the Array renderer? 2/3 of your class is copy-pasted from there. 2) Why do you have some hardcoded HTML inside the renderer? I can't really comment on its behaviour, since I'm not using Smarty and don't have code to run, so you'll have to wait for someone who does. I'd suggest trying the Smarty mailing lists once again, active ones this time. ;] > This was developed under PHP 5.3 on Linux. > > To see how this plugs together see a tutorial set that I have at: > > http://www.phcomp.co.uk/TechTutorial/QfSmarty/index.php > > (This runs the QuickForm and NOT the QuickForm2 version, but the output > is the same). > > All feedback gratefully accepted. > > This is cross posted to both the PEAR-GENERAL and the SMARTY-DEV > mail lists since it is relevant to both. > > Have fun! -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
|
|
Re: Smarty QuickForm2 RendererOn Thu, Nov 19, 2009 at 04:51:36PM +0300, Alexey Borzov wrote:
> Hi Alain, > > Alain Williams wrote: > >Try again - this time with a proper Subject and with the > >renderer attached. A new version is attached. > >* Renderer.php > You could add this option in your Renderer's constructor, no need to patch > the base class. Hmmm: your class inheritance is complicated - I can't see how to do that. Could I ask you to do that and post a version back. > I had a brief look at your implementation: > 1) Why aren't you extending the Array renderer? 2/3 of your class is > copy-pasted from there. True - I did not realise how small the changes would be. The new version works by taking 2 options to the array renderer: * smarty -- this has most effect * old_compat -- needed for existing templates, prob not neede for new templates > 2) Why do you have some hardcoded HTML inside the renderer? There is now just a small amount in gneration of requirednote. To see how this plugs together see a tutorial set that I have at: http://www.phcomp.co.uk/TechTutorial/QfSmarty/index.php (This runs the QuickForm and NOT the QuickForm2 version, but the output is the same). All feedback gratefully accepted. -- 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> -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php |
| Free embeddable forum powered by Nabble | Forum Help |