Re: [Pear] help with Formbuilder and checkboxes

From: Date: Wed, 18 Oct 2006 14:53:09 +0000
Subject: Re: [Pear] help with Formbuilder and checkboxes
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-25515@lists.php.net to get a copy of this message
On 10/17/06, Marco Sottana <marco.sottana@q-web.it> wrote:
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]-----
I like this second one best, I think. It's your call, however, as these 2 solutions are different. One uses advchekcboxes and one uses advmultiselect. I'd also like to again encourage you to use a crossLink. It looks like you already have a table set up for the options that you can choose. Using a many-many table (crossLink) will make your database schema more normalized.
Original Message -----From: "Justin Patrin" <papercrane@gmail.com>To: "Marco Sottana" <marco.sottana@q-web.it> [snip]
Looks like your mailer screwed up the e-mail here.... -- Justin Patrin

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