RE: [PEAR] QuickForm Attribute String
| From: | Jochem Maas \(E-mail\) | Date: | Sat, 12 Apr 2003 10:18:43 +0000 |
| Subject: | RE: [PEAR] QuickForm Attribute String | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-4812@lists.php.net to get a copy of this message | ||
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Firstly,
I do like QuickForm! can't wait to see it running with a
template engine (I currently use the $template object from
phpBB when I need one.) & thanks for the reply!
I'm just getting to know my way round PEAR so forgive
if I sound newbie-ish!
- ----
I have taken the liberty of attaching the complete script
file (227), its actually included from within index.php
which does nothing more than spit out the basic HTML
document, i.e. everything but the 'content' of the current
page.
(the file won't run as it is. remove line 26 and 29 -> 33
if you run it expect an error if you manage to successfully
validate & confirm the form as the script try to include an
emailer class.)
The javascript error occurred because the function was
not defined. this happened after a validate() whilst
showing the the form in FREEZE mode. (at that time I was
removing a required element after freezing and validation,
see below). The problem was I had an onsubmit event defined
for the form pointing a non-existent function, however the
<script> tags were part of the output (there was nothing
between them)
I have just checked this again:
removing the overloaded _getAttrString function
causes the onsubmit to be added to the form tag.
I nolonger see any <script> tags empty or otherwise.
- ----
I had seperate problems with removing a required element
(see line 212) after the 1st validation. - originally I
was not re-creating that element as a 'hidden' - which is
why the validation kept failing on the second submit
I was expecting the rules not to be run because the element
was gone but this is not the case. If you comment out
line 213 you can never successfully confirm the submission.
I was using this dummy element (elementName = 'ghosty') to
allow a rule to be checked that was not aimed at 1 particular
element using a function. I could not getthe rule to run if
I added it to a 'checkbox' or 'hidden' element; finally I
noticed that the rule in question (see line 39 & 115) only
seems to run if the element its attached to also has a
'server' 'required' rule attached.
Which leads to another question...! is it possible to setup rules
at the form level? i.e. not attached to a particular element but
run whenever the form is validated (I guess that this would only
be relevant for 'function' type rules.)
Rgds,
Jochem
I'll try to see if I can cc this to the pear-general list
you never know! (I'll even change the from address...)
>>-----Original Message-----
>>From: Bertrand Mansion [mailto:bmansion@mamasam.com]
>>Sent: Saturday, April 12, 2003 10:49 AM
>>To: Jochem Maas
>>Subject: Re: [PEAR] QuickForm Attribute String
>>
>>
>><jdmaas@chello.nl> wrote :
>>
>>>
>>> -----BEGIN PGP SIGNED MESSAGE-----
>>> Hash: SHA1
>>>
>>> I can't seem to post to the pear general list
>>> (bloody outlook + mulitple adresses headache!)
>>> so I thought I would mail you direct
>>> (as your the maintainer for Quickforms):
>>>
>>> my problem is/was this:
>>>
>>> I have a form - which has client side validation - it gets
>>submitted I send
>>> it back for a confirmation in freeze mode then when the
>>user hits confirm
>>> BANG there a javascript error.
>>> Obviously what happened was that the onsubmit attribute was
>>still in the Form
>>> attributes array. I would have expected freezing the form
>>to remove that
>>> (as it does with the rest of the clientside validation)
>>>
>>> We I solved it by adding the following function to QuickForm:
>>> (overriding the function in the base class - which I used
>>as the basis!)
>>>
>>> <code>
>>>
>>> // {{{ getAttributesString()
>>> /**
>>> * Returns an HTML formatted attribute string
>>> * @param array $attributes
>>> * @return string
>>> * @access private
>>> */
>>> function _getAttrString($attributes)
>>> {
>>> $strAttr = '';
>>> if (is_array($attributes)) {
>>> while (list($key, $value) = each($attributes)) {
>>> if ( isset( $this ) )
>>> {
>>> if (strtolower($key) == 'onsubmit' &&
>>$this->_freezeAll ) {
>>> continue;
>>> }
>>> }
>>> if (is_int($key)) {
>>> $strAttr .= ' ' . strtolower($value) . '="'
>>> .
>>> strtolower($value) . '"';
>>> } else {
>>> $strAttr .= ' ' . strtolower($key) . '="' .
>>> htmlspecialchars($value) . '"';
>>> }
>>> }
>>> }
>>> return $strAttr;
>>> } // end func _getAttrString
>>>
>>> </code>
>>>
>>> maybe you can use this in some way.
>>
>>The form should pass the javascript test even in frozen
>>because elements
>>still exists, they are just converted to hidden fields. If
>>you want, you can
>>send me the piece of code that makes the 'BANG'.
>>
>>Bertrand Mansion
>>Mamasam
>>
-----BEGIN PGP SIGNATURE-----
Version: PGP 7.0.4
iQA/AwUBPpfoAwLRjWHC5uGtEQLIIQCgnr9rjYcwTwCgLdf3heriYI/Nkb8Anjg8
xqDZuYowhmvMP3VciEZYYkwl
=4b7B
-----END PGP SIGNATURE-----