Re: HTMLQuickform: Groups, grouping elements graphically, but leaving them ungroup programmatically

From: Date: Sun, 06 Feb 2005 19:55:14 +0000
Subject: Re: HTMLQuickform: Groups, grouping elements graphically, but leaving them ungroup programmatically
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-17412@lists.php.net to get a copy of this message
Please use plain-text e-mails for this list in the future. In-line comments are, as you can see, nearly impossible with the HTML mail you sent me. In fact, what's below isn't really readable at all... Actually, you can still give your group a name. The thing you want to do is send false for appendName in the addGroup call. $form->addGroup($arr, 'groupName', 'Label', '', false); Grouped elements are still part of the form and exportValues should still give it to you. If it doesn't this is a bug. If exportValue doesn't work, try exportValues (note the 's'). If neither work, file a bug report. Hmmm, after looking it seems you're right, exportValue / values may not pick up group elements. This doesn't seem right, though, I suggest you file a bug report for it. In the meantime you can always use getSubmitValues or getSubmitValue. On Sun, 06 Feb 2005 17:59:30 +0000, Aaron <aaron@rare.as> wrote: > Hi Justin, > thanks for your reply. please read comments further down the page. > > Justin Patrin wrote: > On Sat, 05 Feb 2005 15:39:43 +0000, Aaron <lists.php.net@rare.as> wrote: > Hi there, I have googled for a soloution to this, but there is no solid > source of docmentation that I could find regarding HTML quickform groups. I > have also logged in to irc but had no joy there either. I have read through > most of the documentation for QF but there are missing bits =/ So this is my > current last resort. I want to graphically group several checkbox elements > together, as they apply to a common theme. Using css with a group Element, I > can have the checkboxes nicely and graphically layed out in a group like > format. However I want to be able to access the values of these elements as > if they were not in a group. Which would make it simpler programatically to > set the boolean values in-to mysql as I currently do not know of a way to do > this with grouped elements on just one line. e.g. mysql_field = " . > intval($element->getChecked()) ." Q2. How about accesing those grouped > element values with *one line* of script then, is this possible? I guess I > want to do something like e.g. > $groupElement->getElement('open_to_females')->getChecked(); (obviously this > doesn't work; can you tell i'm still learning php?) I know that one > soloution is to bypass the quickform methods and access the values directly > from the post/get variables, but this seems a bit tardy to me. Well....they > way (IMHO) that you're supposed to process QF values is with the process() > method. function processForm($values) { echo $values['element']; } > $form->process('processForm'); This gives you an assoc array of all of the > submitted values and doesn't do any grouping (unless, of course, you told QF > to prefix the names with the group name). You can also use: $values = > $form->exportValues(); echo $values['element']; I use: > $elementValue = $form->exportValue('elementName'); > > to retreive the values of most elements created, however; grouped element > value's can not be retreived using this method... If you specify a name for > the group you put them in. > > After reading your comments I started to write a reply, but something odd > struck me and after re-reading I noticed the bit "...and doesn't do any > grouping (unless, of course, you told QF to prefix the names with the group > name)." > So that was my first problem, and it is now solved simply by not naming the > groupElement. Thanks. > > > However, in a group... > e.g. > $arr_Open_to = array(); > $arr_Open_to[] =& > > HTML_QuickForm::createElement('checkbox','Open_to_guests',null,'Guests', > ($arr_values['Open_to_guests'] == > 1?"checked=\"checked\"":"") ); > $arr_Open_to[] =& > > HTML_QuickForm::createElement('checkbox','Open_to_trialmembers',null,'Trial > Members', ($arr_values['Open_to_trialmembers'] == > 1?"checked=\"checked\"":"") ); > > $form->addGroup($arr_Open_to, null, 'Open To', null); > > ...the added elements to the array are not added to the form, so the > variables are not accessable by using exportValue(). So I am still left with > retreiving the information directly from the query string. > > message ends > > cheers > Aaron > > > if you don't want to use a callback. > ------ Next Question I populate most variables by simply passing the array > of mysql values to the $form->setDefaults method. e.g. $arr_values = > mysql_fetch_assoc(mysql_query("SELECT * FROM event WHERE EventID = > $EventID")); $form->setDefaults($arr_values); $arr_Open_to[] =& > > HTML_QuickForm::createElement('checkbox','Open_to_females',null,'Females', > ($arr_values['Open_to_females'] == > 1?"checked=\"checked\"":"") ); Q1. Anyone > know if there is away to set the default checked value of a checkbox element > to "checked/unchecked" by using $form->setDefaults or something similar? > Using setDefaults should work fine (I recently had cause to try this with > FormBuilder). Did you try? !DSPAM:42065dc230557092819856! -- Justin Patrin

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