/** * read_preset_form generates a quickform-object to choose the announcement-preset, * if validated redirect to announcement.php?id=new&cid=$id * * @param object $calendar the actual calendarentry * @return object quickform-object to choose the preset, if validated redirect to new announcement */ private function read_preset_form(&$calendar) { // check sort or from/to $sort = $from = $to = ''; if ($this->get('sort') !== false) { $sort = "&sort=" . $this->get('sort'); } if ($this->get('from') !== false) { $from = "&from=" . $this->get('from'); } if ($this->get('to') !== false) { $to = "&to=" . $this->get('to'); } // form-object $form = new HTML_QuickForm2('choose_preset_' . $calendar->get_id(), 'post', array('name' => 'choose_preset_' . $calendar->get_id(), 'action' => 'calendar.php?id=listall' . $sort . $from . $to)); // add selectfield $select = $form->addSelect('preset', array()); $options = array(0 => parent::lang('class.CalendarView#read_preset_form#select#choosePreset')); $options = $options + Preset::read_all_presets('calendar'); $select->loadOptions($options); $select->addRule('callback', parent::lang('class.CalendarView#read_preset_form#rule#select'), array($this, 'callback_check_select')); // add submit $submit = $form->addSubmit('submit', array('value' => parent::lang('class.CalendarView#read_preset_form#select#submit'))); // validate if ($form->validate()) { // get data $data = $form->getValue(); // insert preset_id in calendar-entry $update = array('preset_id' => $data['preset']); $calendar->update($update); $calendar->write_db('update'); // redirect to listall header('Location: calendar.php?id=listall' . $sort . $from . $to); exit; } else { return $form; } }
/** * If data source contains explicitly provided null values, those should be used * @link http://pear.php.net/bugs/bug.php?id=20295 */ public function testBug20295() { $form = new HTML_QuickForm2('bug20295'); $ms = $form->addSelect('multiselect', array('multiple'))->loadOptions(array('one' => 'First option', 'two' => 'Second option'))->setValue(array('two')); // data source searching should stop on finding this null $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('multiselect' => null))); $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('multiselect' => array('one')))); $this->assertNull($ms->getValue()); }
public function testSelectMultipleRecursive() { $form = new HTML_QuickForm2('filters', 'post', null, false); $select = $form->addSelect('baz', array('multiple' => 'multiple'))->loadOptions(array('VALUE1' => 'VALUE1', 'VALUE2' => 'VALUE2', 'VALUE3' => 'VALUE3')); $select->addRecursiveFilter('strtolower'); $this->assertEquals(array('value1', 'value2'), $select->getValue()); }