/** * add * inserts a new radio button. * * example: * * $myradio = new JamHorzRadioButtons(); * $myradio->add('Blue','B'); * $myradio->add('Red','R'); * * @param mixed $labelText the radio label text * @param string $value the radio value * @param mixed $boolChecked true if this radio option must be checked * @access public * @return the full JamPanel created */ public function add($labelText, $value = 'X', $boolChecked = false) { $radio_id = $this->_name . '_' . $this->_count; $this->_count++; $label = new JamElement('label', $labelText); $label->setHtmlOption('for', $radio_id); $input = new JamElement('input'); $input->setId($radio_id); $input->setHtmlOption('name', $this->_name); $input->setHtmlOption('type', 'radio'); $input->setHtmlOption('value', $value); if ($boolChecked == true) { $input->setHtmlOption('checked', 'checked'); } $hpanel = parent::add(new JamHorzPanel()); $hpanel->setBorderNone(); $hpanel->add($label); $hpanel->add($input); return $hpanel; }
/** * row * create a table TR and TD elements * * this example will add a single ROW (TR) containing two TD elements. * * table->row( * 'single value', * array('text'=>'td content', 'htmlOptions'=>array(...)) * ); * * htmlOptions is an array of valid html options, as an example: * array('style'=>'color: red', 'alt'=>'abc', 'id'=>'mycell') * * * @param mixed $def definition for each TD * @param array $commonHtmlOptions common htmlOptions for each TD * @return the new JamElement created (the TR row) */ public function row($def, $commonHtmlOptions = array()) { $row = new JamHorzPanel('tr'); $row->setHtmlOption('class', ''); foreach ($def as $item) { if (is_array($item)) { $col = $row->add(new JamElement('td', $item['text']), false); // default options $col->setHtmlOption('style', $this->tdStyle); // common options if ($commonHtmlOptions != null) { foreach ($commonHtmlOptions as $opt => $val) { $col->addHtmlOption($opt, $val); } } // specific options if (isset($item['htmlOptions'])) { if (is_array($item['htmlOptions'])) { foreach ($item['htmlOptions'] as $opt => $value) { $col->addHtmlOption($opt, $value); } } } } else { $col = $row->add(new JamElement('td', $item), false); // default option $col->setHtmlOption('style', $this->tdStyle); // common options if ($commonHtmlOptions != null) { foreach ($commonHtmlOptions as $opt => $val) { $col->addHtmlOption($opt, $val); } } } } return $this->add($row, false); }
$allLabels[] = $label; $firstname = $form->add(new JamElement('input')); $firstname->setId('firstname'); // a Radio Buttons $label = $form->add(new JamElement('label', 'Gender:')); $radio = $form->add(new JamHorzRadioButtons('gender')); $radio->add('Male'); $radio->add('Female'); $allLabels[] = $label; // checkboxes $label = $form->add(new JamElement('label', 'Do you like Jamboree ?')); $checkbox = $form->add(new JamElement('input')); $checkbox->setHtmlOption('type', 'checkbox'); $checkbox->setHtmlOption('checked', 'checked'); $allLabels[] = $label; $bottomPanel = new JamHorzPanel(); $bottomPanel->setBgColor('#def'); $submit = $bottomPanel->add(new JamElement('input')); $submit->setHtmlOption('type', 'submit'); $submit->setHtmlOption('value', 'Send'); $form->add($bottomPanel); foreach ($allLabels as $label) { $label->setColor('darkred'); $label->addHtmlOption('style', 'font-weight: bold;'); } $form->setId('myform'); $form->setHtmlOption('method', 'post'); $form->setHtmlOption('action', CHtml::normalizeUrl(array('/site/test'))); $form->setWidth('200px'); $form->render(); ?>