Re: [Pear] help with Formbuilder and checkboxes
| From: | Marco Sottana | Date: | Wed, 18 Oct 2006 06:54:10 +0000 |
| Subject: | Re: [Pear] help with Formbuilder and checkboxes | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-25492@lists.php.net to get a copy of this message | ||
Hallo,thank you for your answer, I've have solve the problem in another way.
I've find two new code solutions, could you seen them, what do you think about?
first solution
[code]
function preProcessForm(&$data) {
if(isset($data['checkbox_intention'])) {// controllo
if(is_array($data['checkbox_intention'])){//se e' vuoto darebbe un warning
//$data['checkbox_intention']=array_diff($data['checkbox_intention'],array(null));
$data['checkbox_intention']=implode(",",$data['checkbox_intention']);
print_r($data['checkbox_intention']);
}
}
}
function preGenerateForm() {
$this->checkbox_intention=explode(",",$this->checkbox_intention);
$box=array();
$box[]=& HTML_QuickForm::createElement('advcheckbox','',null, 'label A',null,'10');
$box[]=& HTML_QuickForm::createElement('advcheckbox','',null, 'label B',null,'6');
$box[]=& HTML_QuickForm::createElement('advcheckbox','',null, 'label C',null,'21');
$box[]=& HTML_QuickForm::createElement('advcheckbox','',null, 'label C1',null,'22');
$box[]=& HTML_QuickForm::createElement('advcheckbox','',null, 'label D',null,'13');
$group =& new HTML_QuickForm_group('checkbox_intention', 'Intention', $box);
$this->fb_preDefElements['checkbox_intention'] =& $group;
}
[/code]
second solution
[code]
function preProcessForm(&$data) {
if(isset($data['checkbox_intention'])) {// controllo
if(is_array($data['checkbox_intention'])){//se e' vuoto darebbe un warning
//$data['checkbox_intention']=array_diff($data['checkbox_intention'],array(null));
$data['checkbox_intention']=implode(",",$data['checkbox_intention']);
print_r($data['checkbox_intention']);
}
}
}
function preGenerateForm() {
global $dsn;
if (class_exists('HTML_QuickForm')) {
HTML_QuickForm::registerElementType('advmultiselect','HTML/QuickForm/advmultiselect.php','HTML_QuickForm_advmultiselect');
}
//$dsn = 'mysql://root:@localhost/coopservizi';
$this->checkbox_intention=explode(",",$this->checkbox_intention);
$this->fb_preDefElements['checkbox_intention'] =& HTML_QuickForm::createElement('advmultiselect', 'checkbox_intention', 'intention');
$sql=" select * from tbl_gruppi ";
$this->fb_preDefElements['checkbox_intention']->loadQuery($dsn,$sql,"nome","id");}[/code]----- Original Message -----From: "Justin Patrin" <papercrane@gmail.com>To: "Marco Sottana" <marco.sottana@q-web.it>Cc: <pear-general@lists.php.net>Sent: Tuesday, October 17, 2006 9:55 PMSubject: Re: [PEAR] [Pear] help with Formbuilder and checkboxes> On 10/17/06, Marco Sottana <marco.sottana@q-web.it> wrote:>> > marco schrieb:>> >> [code]>> >> function preGenerateForm()>> >> {>> >> $this->fb_preDefElements['alive'] =>> >> HTML_QuickForm::>> >> createElement('advcheckbox','alive','Ali>> >> ve',null,null,$this->alive);>> >> }>> >> [/code]>> >> this code generate a only one checkbox..>> >> i would like to generate a list of checkbox so i tryed [code]>> >> function preGenerateForm(&$fb) { $box=array(); $box[]=&>> >> HTML_QuickForm::createElement('advcheckbox','checkbox_intention',null,>> >> '0',null,'0'); $box[]=&>> >> HTML_QuickForm::createElement('advcheckbox','checkbox_intention',null,>> >> '1',null,'1'); $box[]=&>> >> HTML_QuickForm::createElement('advcheckbox','checkbox_intention',null,>> >> '2',null,'2'); $this->fb_preDefElements['checkbox_intention'] =>> >> $box; }>> >> [/code]>> >> but this don't save correctly.. field called "checkbox_intention" is a>> >> varchar(200) and a i would like>> >> to save as a list>> >> so if i generate []labelA []labelB []labelC []labelD and i checkA,C>> >> i save in my>> >> field "valueA,ValueC">> >> please help me.. i just send my request of help in forum.. but nobody>> >> answer me>> >>> > Hi Marco,>> >>> > I read your code and your description, and I am still not sure I>> > understand what you want to achieve. Please try to rephrase.>> >>> > If your problem is that the elements are not being properly grouped>> > together, try to put the array of elements into a QuickForm group:>> >>> > $group =& new HTML_QuickForm_group('checkbox_intention', 'Intention',>> > $box);>> > $this->fb_preDefElements['checkbox_intention'] =& $group;>> >>> > See also:>> >http://pear.php.net/manual/en/package.html.html-quickform.php#package.html.html-quickform.groups>> >>> > CU>> > Markus>>>>>> Hallo Marcus,>> Thanks a lot for your availability,>>>> i update my code so :>>>> [code]>> function preGenerateForm() {>> $box=array();>> $box[]=&>> HTML_QuickForm::createElement('advcheckbox','checkbox_intention',null,>> '0',null,'0');>> $box[]=&>> HTML_QuickForm::createElement('advcheckbox','checkbox_intention',null,>> '1',null,'1');>> $box[]=&>> HTML_QuickForm::createElement('advcheckbox','checkbox_intention',null,>> '2',null,'2');>> $group =& new HTML_QuickForm_group('checkbox_intention', 'Intention',>> $box);>> $this->fb_preDefElements['checkbox_intention'] =& $group;>> }>> [/code]>>>> but it makes an error>>>> [error]>> Notice: Array to string conversion in/usr/share/php5/PEAR/DB/DataObject.php>> on line 1218>> [/error]>>>> [input]>> Intention 0 1 2>> [/input]>>>> even if i check 0 and 1 and 2 in output>>>> [output]>> Intention [ ]0 [ ]1 [x]2>> [/output]>>>> Your suggest is near to the correct code version but as you've seen up,>> there's also some problemes, please help me another one>>>>>> What you're asking for is normally called a SET and this isn't> supported. However, you would get the exact same thing using> crossLinks. To do this, create a table such as: checkboValue with> fields id and name. I'm assuming you have a table named record with an> id in it as well. You then set up a table names record_checkboxValues> with fields checkboxValue_id and record_id which link to the> checkboxValue table and record table.>> In the record DO you set:> var $fb_crossLinks = array(array('table' => 'record_checkboxValue'));> in the checkboxValue DO you set:> var $fb_linkDisplayFields = array('name');>> Then you have what you're looking for.>> For an example see:> http://pear.reversefold.com/example/?table=movie&record=4> The Songs section is a crossLink (although it is also using> crossLinkExtraFields).>> If you'd like source (may notbe fully up to date):> http://pear.reversefold.com/example/source/example.tgz>> --> Justin Patrin>