Re: HTML_QuickForm Form Elements Error Issue

From: Date: Wed, 02 Mar 2005 02:45:52 +0000
Subject: Re: HTML_QuickForm Form Elements Error Issue
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-17773@lists.php.net to get a copy of this message
OK, so I am going to reply to myself and see what you guys think. I found the problem / quirk / bug / issue...Definitely interesting and raises some questions for me. After lots of debugging... It turned out that, because my form elements were named numerically, ie <input type="radio" name="1003" value="2003">yes <input type="radio" name="1003" value="2004">no once the names rolled over so they were over 1000, the form did not treat them as required: even though they had their required properties set to true, and I could confirm this from echoing out from with QuickForm.php, they were not seen, in the following function, as required. function isElementRequired($element) { return in_array($element, $this->_required, true); } // end func isElementRequired When I changed their names randomly to start with "q" (just to try a string), the whole thing worked. This is why I had never seen this before -- we had gone through 999 test choices with it working just fine. It has something to do with the strict flag on in_array. So I either need to change all my element names to strings, or... remove the strict flag in the above function. I can do one of two things. Both work, I have tested. 1. Leave my elements named as they are and change the line in isElementRequired to: return in_array($element, $this->_required); ie, remove the strict flag OR 2. Change my element names to strings. Since we are live I would rather do the former, at least as a stop gap till I can test the latter. Can someone tell me if this is inviting any other danger I'm not considering -- if I remove the strict flag from return in_array($element, $this->_required, true); ? What would be the implications? Am I OK to do this for a few days? Does it matter if I do it for the long run? Is it bad to have named the elements numerically in the first place? Thanks very much. Sarah Sarah Gray wrote: > Hi -- > > I'm having a bizarre behaviour -- I have a form which is a series of > questions, a test When creating the form, I apply the "required" rule > to every element in the form in a loop like this: > > $form->addRule($question->question_id, 'Required', 'required'); > > and when I layout the form I put an asterisk by each element, like so: > > {if $element.required}<span class="error">*</span>{/if} > > Every single element is asterisked, as it should be. > > BUT when I submit the form and printout the error array (for debugging > purposes), only the first ten elements are in it -- and you can > successfully submit the form without checking anything but the first ten > elements! > . > This didn't use to be the case -- I don't know where the bug came from > and it's come at a terribly bad time. I'm really flummoxed how elements > could have the element.required property and not stop the browser from > submitting if they are not selected. > > Does anyone have any suggestions / hints / help? I'm pretty lost at the > moment -- and this bug came out of seemingly nowhere -- it did not use > to behave like this but I haven't changed any of my PEAR packages. > > Thanks, > > Sarah > > -- > PEAR General Mailing List (http://pear.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.pear.general (#17773) next »