/** * 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'); $hs = $form->addHierselect('hs')->loadOptions(array($this->_primary, $this->_secondary))->setValue(array(1, 12)); $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('hs' => null))); $this->assertNull($hs->getValue()); }
public function testSetValueFromSubmitDataSource() { $form = new HTML_QuickForm2('image', 'post', null, false); $foo = $form->appendChild(new HTML_QuickForm2_Element_InputImage('foo')); $bar = $form->appendChild(new HTML_QuickForm2_Element_InputImage('bar[idx]')); $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('foo_x' => '1234', 'foo_y' => '5678', 'bar' => array('idx' => array('98', '76'))))); $this->assertEquals(array('x' => '12', 'y' => '34'), $foo->getValue()); $this->assertEquals(array('x' => '56', 'y' => '78'), $bar->getValue()); $foo->setAttribute('disabled'); $this->assertNull($foo->getValue()); }
public function testSetValueFromSubmitDataSource() { $form = new HTML_QuickForm2('submit', 'post', null, false); $foo = $form->appendChild(new HTML_QuickForm2_Element_InputSubmit('foo')); $bar = $form->appendChild(new HTML_QuickForm2_Element_InputSubmit('bar')); $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('foo' => 'Default for foo', 'bar' => 'Default for bar'))); $this->assertEquals('A button clicked', $foo->getValue()); $this->assertNull($bar->getValue()); $foo->setAttribute('disabled'); $this->assertNull($foo->getValue()); }
function printForm($data = array()) { foreach (array('name', 'email', 'copy_me', 'subject', 'text') as $value) { if (!isset($data[$value])) { $data[$value] = ''; } } $form = new HTML_QuickForm2('contect', 'post', array('action' => '/account-mail.php?handle=' . htmlspecialchars($_GET['handle']))); $form->removeAttribute('name'); // Set defaults for the form elements $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('name' => htmlspecialchars($data['name']), 'email' => htmlspecialchars($data['email']), 'copy_me' => htmlspecialchars($data['copy_me']), 'subject' => htmlspecialchars($data['subject']), 'text' => htmlspecialchars($data['text'])))); $form->addElement('text', 'name', array('required' => 'required'))->setLabel('Y<span class="accesskey">o</span>ur Name:', 'size="40" accesskey="o"'); $form->addElement('email', 'email', array('required' => 'required'))->setLabel('Email Address:'); $form->addElement('checkbox', 'copy_me')->setLabel('CC me?:'); $form->addElement('text', 'subject', array('required' => 'required', 'size' => '80'))->setLabel('Subject:'); $form->addElement('textarea', 'text', array('cols' => 80, 'rows' => 10, 'required' => 'required'))->setLabel('Text:'); if (!auth_check('pear.dev')) { $numeralCaptcha = new Text_CAPTCHA_Numeral(); $form->addElement('number', 'captcha', array('maxlength' => 4, 'required' => 'required'))->setLabel("What is " . $numeralCaptcha->getOperation() . '?'); $_SESSION['answer'] = $numeralCaptcha->getAnswer(); } $form->addElement('submit', 'submit')->setLabel('Send Email'); print $form; }
<?php if ('@data_dir@' != '@' . 'data_dir@') { $filename = '@data_dir@/HTML_QuickForm2/quickform.css'; } else { $filename = dirname(dirname(dirname(__FILE__))) . '/data/quickform.css'; } readfile($filename); ?> </style> <title>HTML_QuickForm2 dualselect example: custom element and renderer plugin</title> </head> <body> <?php $options = array(4 => "Afghanistan", 8 => "Albania", 12 => "Algeria", 20 => "Andorra", 24 => "Angola", 28 => "Antigua and Barbuda", 32 => "Argentina", 51 => "Armenia", 36 => "Australia", 40 => "Austria", 31 => "Azerbaijan", 44 => "Bahamas", 48 => "Bahrain", 50 => "Bangladesh", 52 => "Barbados", 112 => "Belarus", 56 => "Belgium", 84 => "Belize", 204 => "Benin", 64 => "Bhutan", 68 => "Bolivia", 70 => "Bosnia and Herzegovina", 72 => "Botswana", 76 => "Brazil", 96 => "Brunei Darussalam", 100 => "Bulgaria", 854 => "Burkina Faso", 108 => "Burundi", 116 => "Cambodia", 120 => "Cameroon", 124 => "Canada", 132 => "Cape Verde", 140 => "Central African Republic", 148 => "Chad", 152 => "Chile", 156 => "China", 170 => "Colombia", 174 => "Comoros", 178 => "Congo", 180 => "Congo, Democratic Republic of", 184 => "Cook Islands", 188 => "Costa Rica", 384 => "Cote D'Ivoire", 191 => "Croatia", 192 => "Cuba", 196 => "Cyprus", 203 => "Czech Republic", 208 => "Denmark", 262 => "Djibouti", 212 => "Dominica", 214 => "Dominican Republic", 218 => "Ecuador", 818 => "Egypt", 222 => "El Salvador", 226 => "Equatorial Guinea", 232 => "Eritrea", 233 => "Estonia", 231 => "Ethiopia", 242 => "Fiji", 246 => "Finland", 250 => "France", 266 => "Gabon", 270 => "Gambia", 268 => "Georgia", 276 => "Germany", 288 => "Ghana", 300 => "Greece", 308 => "Grenada", 320 => "Guatemala", 324 => "Guinea", 624 => "Guinea-Bissau", 328 => "Guyana", 332 => "Haiti", 336 => "Holy See (Vatican City State)", 340 => "Honduras", 348 => "Hungary", 352 => "Iceland", 356 => "India", 360 => "Indonesia", 364 => "Iran", 368 => "Iraq", 372 => "Ireland", 376 => "Israel", 380 => "Italy", 388 => "Jamaica", 392 => "Japan", 400 => "Jordan", 398 => "Kazakhstan", 404 => "Kenya", 296 => "Kiribati", 408 => "Korea, Democratic People's Republic of", 410 => "Korea, Republic of", 414 => "Kuwait", 417 => "Kyrgyz Republic", 418 => "Laos", 428 => "Latvia", 422 => "Lebanon", 426 => "Lesotho", 430 => "Liberia", 434 => "Libya", 438 => "Liechtenstein", 440 => "Lithuania", 442 => "Luxembourg", 807 => "Macedonia", 450 => "Madagascar", 454 => "Malawi", 458 => "Malaysia", 462 => "Maldives", 466 => "Mali", 470 => "Malta", 584 => "Marshall Islands", 474 => "Martinique", 478 => "Mauritania", 480 => "Mauritius", 484 => "Mexico", 583 => "Micronesia", 498 => "Moldova", 492 => "Monaco", 496 => "Mongolia", 499 => "Montenegro", 504 => "Morocco", 508 => "Mozambique", 104 => "Myanmar", 516 => "Namibia", 520 => "Nauru", 524 => "Nepal", 528 => "Netherlands", 554 => "New Zealand", 558 => "Nicaragua", 562 => "Niger", 566 => "Nigeria", 570 => "Niue", 578 => "Norway", 512 => "Oman", 586 => "Pakistan", 585 => "Palau", 591 => "Panama", 598 => "Papua New Guinea", 600 => "Paraguay", 604 => "Peru", 608 => "Philippines", 616 => "Poland", 620 => "Portugal", 634 => "Qatar", 642 => "Romania", 643 => "Russian Federation", 646 => "Rwanda", 882 => "Samoa", 674 => "San Marino", 678 => "Sao Tome and Principe", 682 => "Saudi Arabia", 686 => "Senegal", 688 => "Serbia", 690 => "Seychelles", 694 => "Sierra Leone", 702 => "Singapore", 703 => "Slovakia", 705 => "Slovenia", 90 => "Solomon Islands", 706 => "Somalia", 710 => "South Africa", 724 => "Spain", 144 => "Sri Lanka", 659 => "St. Kitts and Nevis", 662 => "St. Lucia", 670 => "St. Vincent and the Grenadines", 736 => "Sudan", 740 => "Suriname", 748 => "Swaziland", 752 => "Sweden", 756 => "Switzerland", 760 => "Syria", 158 => "Taiwan", 762 => "Tajikistan", 834 => "Tanzania", 764 => "Thailand", 626 => "Timor-Leste", 768 => "Togo", 776 => "Tonga", 780 => "Trinidad and Tobago", 788 => "Tunisia", 792 => "Turkey", 795 => "Turkmenistan", 798 => "Tuvalu", 800 => "Uganda", 804 => "Ukraine", 784 => "United Arab Emirates", 826 => "United Kingdom of Great Britain & N. Ireland", 840 => "United States of America", 858 => "Uruguay", 860 => "Uzbekistan", 548 => "Vanuatu", 862 => "Venezuela", 704 => "Viet Nam", 732 => "Western Sahara", 887 => "Yemen", 894 => "Zambia", 716 => "Zimbabwe"); $form = new HTML_QuickForm2('dualselect'); $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('destinations' => array(4, 148, 180, 368, 706, 736, 716)))); $fs = $form->addElement('fieldset')->setLabel('A custom "dualselect" element using a renderer plugin for output'); $ds = $fs->addElement('dualselect', 'destinations', array('size' => 10, 'style' => 'width: 215px; font-size: 90%'), array('options' => $options, 'keepSorted' => true, 'from_to' => array('content' => ' >> ', 'attributes' => array('style' => 'font-size: 90%')), 'to_from' => array('content' => ' << ', 'attributes' => array('style' => 'font-size: 90%'))))->setLabel(array('Popular travel destinations:', 'Available', 'Chosen')); $ds->addRule('required', 'Select at least two destinations', 2, HTML_QuickForm2_Rule::ONBLUR_CLIENT_SERVER); $fs->addElement('checkbox', 'doFreeze', null, array('content' => 'Freeze dualselect on form submit')); $fs->addElement('submit', 'testSubmit', array('value' => 'Submit form')); // outputting form values if ('POST' == $_SERVER['REQUEST_METHOD']) { $value = $form->getValue(); echo "<pre>\n"; var_dump($value); echo "</pre>\n<hr />"; if (!empty($value['doFreeze'])) { $ds->toggleFrozen(true); } }
/** * edit edits the given entry * * @param int $cid entry-id for calendar * @return string html-string */ private function edit($cid) { // check rights if (Rights::check_rights($cid, 'calendar')) { // smarty-templates $sD = new JudoIntranetSmarty(); // get calendar-object $calendar = new Calendar($cid); // pagecaption $this->tpl->assign('pagecaption', parent::lang('class.CalendarView#page#caption#edit') . ": \"{$cid}\" (" . $calendar->get_name() . ")"); // get rights $cRights = $calendar->get_rights()->get_rights(); // check public access $kPublicAccess = array_search(0, $cRights); $publicAccess = false; if ($kPublicAccess !== false) { $publicAccess = true; unset($cRights[$kPublicAccess]); } // prepare return $return = ''; $form = new HTML_QuickForm2('edit_calendar_entry', 'post', array('name' => 'edit_calendar_entry', 'action' => 'calendar.php?id=edit&cid=' . $cid)); $now_year = (int) date('Y'); $year_min = $now_year; $year_max = $now_year + 3; // get datasource $datasource = array('date' => $calendar->get_date(), 'name' => $calendar->get_name(), 'shortname' => $calendar->get_shortname(), 'type' => $calendar->return_type(), 'entry_content' => $calendar->get_content(), 'rights' => $cRights); // add public access if ($publicAccess) { $datasource['public'] = 1; } $form->addDataSource(new HTML_QuickForm2_DataSource_Array($datasource)); // renderer $renderer = HTML_QuickForm2_Renderer::factory('default'); $renderer->setOption('required_note', parent::lang('class.CalendarView#entry#form#requiredNote')); // elements // date $date = $form->addElement('text', 'date', array()); $date->setLabel(parent::lang('class.CalendarView#entry#form#date') . ':'); // rule $date->addRule('required', parent::lang('class.CalendarView#entry#rule#required.date')); $date->addRule('callback', parent::lang('class.CalendarView#entry#rule#check.date'), array($this, 'callback_check_date')); // add jquery-datepicker // smarty $sD->assign('elementid', 'date-0'); $sD->assign('dateFormat', 'yy-mm-dd'); $sD->assign('dateValue', $calendar->get_date()); $this->add_jquery($sD->fetch('smarty.js-datepicker.tpl')); // name $name = $form->addElement('text', 'name'); $name->setLabel(parent::lang('class.CalendarView#entry#form#name') . ':'); $name->addRule('required', parent::lang('class.CalendarView#entry#rule#required.name')); $name->addRule('regex', parent::lang('class.CalendarView#entry#rule#regexp.allowedChars') . ' [' . $_SESSION['GC']->get_config('name.desc') . ']', $_SESSION['GC']->get_config('name.regexp')); // shortname $shortname = $form->addElement('text', 'shortname'); $shortname->setLabel(parent::lang('class.CalendarView#entry#form#shortname') . ':'); $shortname->addRule('regex', parent::lang('class.CalendarView#entry#rule#regexp.allowedChars') . ' [' . $_SESSION['GC']->get_config('name.desc') . ']', $_SESSION['GC']->get_config('name.regexp')); // type $options = array_merge(array(0 => '--'), Calendar::return_types()); $type = $form->addElement('select', 'type'); $type->setLabel(parent::lang('class.CalendarView#entry#form#type') . ':'); $type->loadOptions($options); $type->addRule('required', parent::lang('class.CalendarView#entry#rule#required.type')); $type->addRule('callback', parent::lang('class.CalendarView#entry#rule#check.select'), array($this, 'callback_check_select')); // entry_content $content = $form->addElement('textarea', 'entry_content'); $content->setLabel(parent::lang('class.CalendarView#entry#form#entry_content') . ':'); $content->addRule('regex', parent::lang('class.CalendarView#entry#rule#regexp.allowedChars') . ' [' . $_SESSION['GC']->get_config('textarea.desc') . ']', $_SESSION['GC']->get_config('textarea.regexp')); // select rights $options = $_SESSION['user']->return_all_groups('sort'); $rights = $form->addElement('select', 'rights', array('multiple' => 'multiple', 'size' => 5)); $rights->setLabel(parent::lang('class.CalendarView#entry#form#rights') . ':'); $rights->loadOptions($options); // checkbox public $rights = $form->addElement('checkbox', 'public'); $rights->setLabel(parent::lang('class.CalendarView#entry#form#public') . ':'); // submit-button $form->addElement('submit', 'submit', array('value' => parent::lang('class.CalendarView#entry#form#submitButton'))); // validate if ($form->validate()) { // create calendar-object $data = $form->getValue(); // check $data['rights'] if (!isset($data['rights'])) { $data['rights'] = array(); } // merge with own groups, add admin $data['rights'] = array_merge($data['rights'], $_SESSION['user']->get_groups(), array(1)); // add public access $kPublicAccess = array_search(0, $data['rights']); if ($kPublicAccess === false && isset($data['public']) && $data['public'] == 1) { $data['rights'][] = 0; } elseif ($kPublicAccess !== false && !isset($data['public'])) { unset($data['rights'][$kPublicAccess]); } $calendar_new = array('date' => $data['date'], 'name' => $data['name'], 'shortname' => $data['shortname'], 'type' => $data['type'], 'content' => $data['entry_content'], 'rights' => $data['rights'], 'valid' => 1); // update calendar $calendar->update($calendar_new); // put entry to output // smarty-template $sCD = new JudoIntranetSmarty(); // write entry try { $calendar->write_db('update'); // smarty $sCD->assign('data', $calendar->details_to_html()); return $sCD->fetch('smarty.calendar.details.tpl'); } catch (Exception $e) { $GLOBALS['Error']->handle_error($e); return $GLOBALS['Error']->to_html($e); } } else { return $form->render($renderer); } } else { // error $errno = $GLOBALS['Error']->error_raised('NotAuthorized', 'entry:' . $this->get('id'), $this->get('id')); $GLOBALS['Error']->handle_error($errno); return $GLOBALS['Error']->to_html($errno); } }
$result->close(); } else { // Clear all parameters if a new user will be created. $arrayAlbum = array("", "", "", "", "", "", ""); } /* * Create the form with QuickForm2. */ require_once 'HTML/QuickForm2.php'; require_once 'HTML/QuickForm2/Renderer.php'; // Point back to the same page for validation. $formAction = WS_SITELINK . "?p=edit_alb&id=" . $idAlbum; // Create a new form object. $form = new HTML_QuickForm2('album', 'post', array('action' => $formAction), array('name' => 'album')); // Data source with default values: $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('name' => $arrayAlbum[2], 'description' => $arrayAlbum[3]))); // Album info. $fsAlbum = $form->addElement('fieldset')->setLabel('Album'); $nameAlbum = $fsAlbum->addElement('text', 'name', array('style' => 'width: 300px;'), array('label' => 'Namn')); $nameAlbum->addRule('required', 'Fyll i namn på albumet'); $nameAlbum->addRule('maxlength', 'Namnet är för långt för databasen.', 100); $descriptionAlbum = $fsAlbum->addElement('textarea', 'description', array('style' => 'width: 300px;'), array('label' => 'Beskrivning')); // Buttons $buttons = $form->addGroup('buttons')->setSeparator(' '); $buttons->addElement('image', 'submitButton', array('src' => 'images/b_enter.gif', 'title' => 'Spara')); $buttons->addElement('static', 'resetButton')->setContent('<a title="Återställ" href="?p=edit_alb&id=' . $idAlbum . '" ><img src="images/b_undo.gif" alt="Återställ" /></a>'); $buttons->addElement('static', 'cancelButton')->setContent('<a title="Avbryt" href="?p=' . $redirect . '" > <img src="images/b_cancel.gif" alt="Avbryt" /></a>'); /* * Process the form. */
public function testBug15708() { $form = new HTML_QuickForm2('bug15708'); $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('aRadio' => 1))); $aRadio = $form->appendChild(new HTML_QuickForm2_Element_InputCheckable('aRadio'))->setAttribute('value', 1); $this->assertContains('checked', $aRadio->__toString()); }
while ($row = $st->fetch(PDO::FETCH_ASSOC)) { $materia_select[$row['nombre']] = $row['nombre']; } */ $materia_select = $boolean_select; $form_update = false; if (isset($record_id)) { $form_update = true; } $form = new HTML_QuickForm2('form', 'post'); if ($form_update and empty($_POST)) { $st = $db->prepare('select * from ' . $params['table'] . ' where ' . $params['primary_key'] . ' = ?'); $st->execute(array($record_id)); $edit_row = $st->fetch(PDO::FETCH_ASSOC); $defaults['new_row'] = $edit_row; $form->addDataSource(new HTML_QuickForm2_DataSource_Array($defaults)); } else { // defaults $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('new_row' => array('fecha' => time())))); } $form->addElement('hidden', 'action')->setValue($params['action']); $form->addElement('hidden', 'params')->setValue($form_params); if ($form_update) { $form->addElement('text', 'material_id', array('disabled' => 'disabled'), array('label' => 'Material Id'))->setValue($record_id); } $form->addElement('select', 'new_row[materia]', array('autofocus' => 'autofocus'))->setLabel(' Materia:')->loadOptions($materia_select)->addRule('required', 'Valor requerido'); $form->addElement('text', 'new_row[titulo]')->setLabel('Titulo:')->addRule('required', 'Valor requerido'); $form->addElement('text', 'new_row[autor]')->setLabel('Autor:')->addRule('required', 'Valor requerido'); $form->addElement('text', 'new_row[cant_hojas]')->setLabel('Cant de hojas:')->addRule('required', 'Valor requerido'); $form->addElement('text', 'new_row[carpeta]')->setLabel('Carpeta:')->addRule('required', 'Valor requerido'); $form->addElement('text', 'new_row[folio]')->setLabel('Folio:')->addRule('required', 'Valor requerido');
/** * Get form rendered as html * * @param array $return form parameters * @return string * * @access private */ private function get_form_html($return) { // returns html based on form parameters in $return $out = "<p>" . $return['introduction'] . "</p>" . "\r\n"; $form = new HTML_QuickForm2($return['name'], $return['method'], $return['action']); $form->addDataSource(new HTML_QuickForm2_DataSource_Array($return['values'])); if (count($return['parameters']) > 0) { $fieldset = $form->addElement('fieldset'); foreach (array_keys($return['parameters']) as $key) { if (!in_array($key, $return['exclude'])) { $parameter = $return['parameters'][$key]; $valid_option = array(); if (array_key_exists($key, $return['valid_options'])) { $valid_option = $return['valid_options'][$key]; if ('number' == $valid_option['type']) { $input_type = 'text'; } if ('boolean' == $valid_option['type']) { $input_type = 'checkbox'; } } $value = ''; $fieldset->addElement($input_type, $key)->setLabel($parameter['label']); } } } if (count($return['hidden']) > 0) { $fieldset_hidden = $form->addElement('fieldset'); foreach (array_keys($return['hidden']) as $key) { $value = $return['hidden'][$key]; $fieldset_hidden->addElement('hidden', $key)->setValue($value); } } // add page_id $fieldset->addElement('hidden', 'request')->setValue($return['request']); $fieldset->addElement('hidden', 'page_id')->setValue($_GET['page_id']); $fieldset->addElement('submit', null, array('value' => $return['submit'])); $out .= $form; return $out; }
*/ if (!isset($nextPage)) { die('Direct access to the page is not allowed.'); } /* * Generera formuläret med QuickForm2. */ require_once 'HTML/QuickForm2.php'; require_once 'HTML/QuickForm2/Renderer.php'; // Alternativ för nationalitet. $options = array('--' => '--', 'se' => 'Svensk', 'no' => 'Norsk', 'dk' => 'Dansk', 'fi' => 'Finsk', 'nn' => 'Annan'); $formAction = WS_SITELINK . "?p=appl"; // Pekar tillbaka på samma sida igen. $form = new HTML_QuickForm2('application', 'post', array('action' => $formAction), array('name' => 'application')); // data source with default values: $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('personnummerElev' => 'ååååmmdd-nnnn', 'stadsdelBostad' => 'Mont Kiara, Ampang, ...', 'stadBostad' => 'Kuala Lumpur', 'statBostad' => 'Kuala Lumpur, Selangor, ...', 'skolaElev' => 'MKIS, ISKL, ...'))); // Data för eleven $fsElev = $form->addElement('fieldset')->setLabel('Eleven'); $fornamnPerson = $fsElev->addElement('text', 'fornamnPerson', array('style' => 'width: 300px;'), array('label' => 'Förnamn:')); $fornamnPerson->addRule('required', 'Fyll i elevens förnamn'); $fornamnPerson->addRule('maxlength', 'Elevens förnamn får max vara 50 tecken.', 50); $efteramnPerson = $fsElev->addElement('text', 'efternamnPerson', array('style' => 'width: 300px;'), array('label' => 'Efternamn:')); $efteramnPerson->addRule('required', 'Fyll i elevens efternamn'); $efteramnPerson->addRule('maxlength', 'Elevens efternamn får max vara 50 tecken.', 50); $nationalitetElev = $fsElev->addElement('select', 'nationalitetElev', null, array('options' => $options, 'label' => 'Nationalitet:')); $personnummerElev = $fsElev->addElement('text', 'personnummerElev', array('style' => 'width: 300px;'), array('label' => 'Personnummer:')); $personnummerElev->addRule('required', 'Fyll i elevens personnummer eller födelsedatum.'); $personnummerElev->addRule('regex', 'Personnumret måste ha formen ååååmmdd-nnnn. Födelsedatum formen ååååmmdd.', '/^(19|20)\\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\\d|3[01])(-\\d{4})?$/'); $kommentar = $fsElev->addElement('static', 'comment')->setContent('Fyll i svenskt personnummer om eleven har det, annars födelsedatum.'); $arskursElev = $fsElev->addElement('text', 'arskursElev', array('style' => 'width: 300px;'), array('label' => 'Årskurs i ordinarie skola:'));
public function testSetDataSources() { $ds1 = new HTML_QuickForm2_DataSource_Array(array('key' => 'value')); $ds2 = new HTML_QuickForm2_DataSource_Array(array('another key' => 'foo')); $form = new HTML_QuickForm2('dstest'); $this->assertEquals(0, count($form->getDataSources())); $form->addDataSource($ds2); $this->assertEquals(1, count($form->getDataSources())); $form->setDataSources(array($ds1, $ds2)); $this->assertEquals(2, count($form->getDataSources())); try { $form->setDataSources(array($ds1, 'bogus', $ds2)); } catch (HTML_QuickForm2_InvalidArgumentException $e) { return; } $this->fail('Expected HTML_QuickForm2_InvalidArgumentException was not thrown'); }
public function testSelectMultipleNoOptionsSelectedOnSubmit() { $options = array('1' => 'Option 1', '2' => 'Option 2'); $formPost = new HTML_QuickForm2('multiple', 'post', null, false); $single1 = $formPost->appendChild(new HTML_QuickForm2_Element_Select('single1', null, array('options' => $options))); $single2 = $formPost->appendChild(new HTML_QuickForm2_Element_Select('single2', null, array('options' => $options))); $multiple = $formPost->appendChild(new HTML_QuickForm2_Element_Select('mult', array('multiple'), array('options' => $options))); $this->assertEquals('1', $single1->getValue()); $this->assertNull($single2->getValue()); $this->assertNull($multiple->getValue()); $formPost->addDataSource(new HTML_QuickForm2_DataSource_Array(array('single1' => '2', 'single2' => '2', 'mult' => array('1', '2')))); $this->assertEquals('1', $single1->getValue()); $this->assertEquals('2', $single2->getValue()); $this->assertNull($multiple->getValue()); $formGet = new HTML_QuickForm2('multiple2', 'get', null, false); $multiple2 = $formGet->appendChild(new HTML_QuickForm2_Element_Select('mult2', array('multiple'), array('options' => $options))); $this->assertNull($multiple2->getValue()); $formGet->addDataSource(new HTML_QuickForm2_DataSource_Array(array('mult2' => array('1', '2')))); $this->assertEquals(array('1', '2'), $multiple2->getValue()); }
<p> Note that this account can also be used to report a bug or comment on an existing bug. </p> <p> Please use the "latin counterparts" of non-latin characters (for instance th instead of þ). </p> MSG; echo '<a name="requestform" id="requestform"></a>'; report_error($errors); $form = new HTML_QuickForm2('account-request-vote', 'post', array('action' => 'account-request-vote.php#requestform')); $form->removeAttribute('name'); $renderer = new HTML_QuickForm2_Renderer_PEAR(); $hsc = array_map('htmlspecialchars', $stripped); // Set defaults for the form elements $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('handle' => @$hsc['handle'], 'firstname' => @$hsc['firstname'], 'lastname' => @$hsc['lastname'], 'email' => @$hsc['email'], 'showemail' => @$hsc['showemail'], 'read_everything' => @$hsc['read_everything']))); $form->addElement('text', 'handle', array('placeholder' => 'psmith', 'maxlength' => "20", 'accesskey' => "r", 'required' => 'required'))->setLabel('Use<span class="accesskey">r</span>name:'); $form->addElement('text', 'firstname', array('placeholder' => 'Peter', 'required' => 'required'))->setLabel('First Name:'); $form->addElement('text', 'lastname', array('placeholder' => 'Smith', 'required' => 'required'))->setLabel('Last Name:'); $form->addElement('password', 'password', array('size' => 10, 'required' => 'required'))->setLabel('Password:'******'password', 'password2', array('size' => 10, 'required' => 'required'))->setLabel('Repeat Password:'******'number', 'captcha', array('maxlength' => 4, 'required' => 'required'))->setLabel("What is " . $numeralCaptcha->getOperation() . '?'); $_SESSION['answer'] = $numeralCaptcha->getAnswer(); $form->addElement('email', 'email', array('placeholder' => '*****@*****.**', 'required' => 'required'))->setLabel('Email Address:'); $form->addElement('checkbox', 'showemail')->setLabel('Show email address?'); $form->addGroup('read_everything')->addElement('checkbox', 'comments_read', array('required' => 'required'))->setLabel('I have read EVERYTHING on this page'); $form->addElement('submit', 'submit')->setLabel('Submit Request'); print $form->render($renderer); } response_footer();
public function testCheckboxUncheckedOnSubmit() { $formPost = new HTML_QuickForm2('boxed', 'post', null, false); $box1 = $formPost->appendChild(new HTML_QuickForm2_Element_InputCheckbox('box1')); $box2 = $formPost->appendChild(new HTML_QuickForm2_Element_InputCheckbox('box2')); $this->assertEquals('1', $box1->getValue()); $this->assertNull($box2->getValue()); $formPost->addDataSource(new HTML_QuickForm2_DataSource_Array(array('box2' => '1'))); $this->assertEquals('1', $box1->getValue()); $this->assertNull($box2->getValue()); $formGet = new HTML_QuickForm2('boxed2', 'get', null, false); $box3 = $formGet->appendChild(new HTML_QuickForm2_Element_InputCheckbox('box3')); $this->assertNull($box3->getValue()); $formGet->addDataSource(new HTML_QuickForm2_DataSource_Array(array('box3' => '1'))); $this->assertEquals('1', $box3->getValue()); }
$i--; } } } } } /* * Generera formuläret med QuickForm2. */ require_once 'HTML/QuickForm2.php'; require_once 'HTML/QuickForm2/Renderer.php'; // Peka tillbaka på samma sida igen. $formAction = WS_SITELINK . "?p=edit_acnt&id=" . $idPerson; $form = new HTML_QuickForm2('account', 'post', array('action' => $formAction), array('name' => 'account')); // data source with default values: $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('account' => $arrayPerson[1], 'password' => $pwd, 'passwordRep' => $pwd, 'send' => '0'))); $fsAccount = $form->addElement('fieldset')->setLabel('Användarkonto'); // Användarnamn $accountPerson = $fsAccount->addElement('text', 'account', array('style' => 'width: 300px;'), array('label' => 'Användarnamn:')); $accountPerson->addRule('required', 'Du måste ange ett användarnamn'); $accountPerson->addRule('maxlength', 'Användarnamnet får inte vara längre än 20 tecken.', 20); $accountPerson->addRule('regex', 'Användarnamnet får bara innehålla bokstäver a-z, A-Z.', '/^[a-zA-Z]+$/'); // Lösenord $newPasswordPerson = $fsAccount->addElement('password', 'password', array('style' => 'width: 300px;'), array('label' => 'Lösenord:')); $passwordRep = $fsAccount->addElement('password', 'passwordRep', array('style' => 'width: 300px;'), array('label' => 'Lösenord igen:')); $newPasswordPerson->addRule('required', 'Du måste ange ett lösenord.'); $passwordRep->addRule('required', 'Du måste upprepa lösenordet.'); $newPasswordPerson->addRule('minlength', 'Lösenordet måste innehålla minst 5 tecken.', 5); $newPasswordPerson->addRule('maxlength', 'Lösenordet får inte vara längre än 20 tecken.', 20); $newPasswordPerson->addRule('eq', 'Du har angett två olika lösenord.', $passwordRep); // Skicka lösenord?
$color_select['white'] = 'Blanco'; $form_params = params_encode($params); $form_update = false; if (isset($record_id)) { $form_update = true; } $form = new HTML_QuickForm2('form', 'post', array('role' => 'form')); if ($form_update and empty($_POST)) { $db = new PDO($db_dsn, $db_user, $db_pass); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); $st = $db->prepare('select * from ' . $params['table'] . ' where ' . $params['primary_key'] . ' = ?'); $st->execute(array($record_id)); $edit_row = $st->fetch(PDO::FETCH_ASSOC); $defaults['new_row'] = $edit_row; $form->addDataSource(new HTML_QuickForm2_DataSource_Array($defaults)); } // elements $form->addElement('hidden', 'action')->setValue($params['action']); $form->addElement('hidden', 'params')->setValue($form_params); $form->addElement('text', 'new_row[lista_nombre]', array('autofocus' => 'autofocus', 'maxlength' => '64'))->setLabel('Nombre de la lista:')->addRule('required', 'Valor requerido'); $form->addElement('text', 'new_row[lista_nombre_corto]', array('placeholder' => 'Nombre corto (Opcional)', 'maxlength' => '64'))->setLabel('Nombre corto de la lista:'); $form->addElement('select', 'new_row[activa]')->setLabel('Activa:')->loadOptions($boolean2_select)->addRule('required', 'Valor requerido'); $form->addElement('select', 'new_row[en_total]')->setLabel('Participa en el total:')->loadOptions($boolean2_select)->addRule('required', 'Valor requerido'); $form->addElement('select', 'new_row[en_porcentaje]')->setLabel('Participa en el porcentaje:')->loadOptions($boolean2_select)->addRule('required', 'Valor requerido'); $form->addElement('select', 'new_row[participa_centro]')->setLabel('Participa en Centro:')->loadOptions($boolean2_select)->addRule('required', 'Valor requerido'); $form->addElement('select', 'new_row[participa_claustro]')->setLabel('Participa en Claustro:')->loadOptions($boolean2_select)->addRule('required', 'Valor requerido'); $form->addElement('text', 'new_row[orden]', array('pattern' => '\\d*', 'maxlength' => '6', 'title' => 'Solo digitos'))->setLabel('Orden:')->addRule('required', 'Valor requerido'); $form->addElement('select', 'new_row[color]')->setLabel('Color:')->loadOptions($color_select); $form->addElement('button', 'btnSubmit', array('type' => 'submit', 'value' => 'Guardar', 'class' => 'btn btn-lg btn-primary'))->setContent('Guardar'); // validaciones
public function testUpdateValueFromNewDataSource() { $form = new HTML_QuickForm2('form2'); $el = $form->appendChild(new HTML_QuickForm2_ElementImpl('foo')); $this->assertNull($el->getValue()); $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('foo' => 'updated value'))); $this->assertEquals('updated value', $el->getValue()); }
echo "</fieldset>\n"; } // in real application the password check will a bit be different, of course function check_password($password) { return $password == 'qwerty'; } // // Form setup // require_once 'HTML/QuickForm2.php'; $form = new HTML_QuickForm2('basicRules'); // for file upload to work $form->setAttribute('enctype', 'multipart/form-data'); // data source with default values: $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('testUsername' => 'luser'))); // override whatever value was submitted $form->addElement('hidden', 'MAX_FILE_SIZE')->setValue('102400'); // // Simple fields validation, rule chaining // $fsAuth = $form->addElement('fieldset')->setLabel('Auth credentials'); $username = $fsAuth->addElement('text', 'testUsername', array('style' => 'width: 200px;'))->setLabel('Username (letters only):'); $fsPasswords = $fsAuth->addElement('fieldset')->setLabel('Supply password only if you want to change it'); $oldPassword = $fsPasswords->addElement('password', 'oldPassword', array('style' => 'width: 200px;'))->setLabel('Old password (<i>qwerty</i>):'); $newPassword = $fsPasswords->addElement('password', 'newPassword', array('style' => 'width: 200px;'))->setLabel('New password (min 6 chars):'); $repPassword = $fsPasswords->addElement('password', 'newPasswordRepeat', array('style' => 'width: 200px;'))->setLabel('Repeat new password:'******'required', 'Username is required'); $username->addRule('regex', 'Username should contain only letters', '/^[a-zA-Z]+$/'); // old password should be either left blank or be equal to 'qwerty' $oldPassword->addRule('empty')->or_($oldPassword->createRule('callback', 'Wrong password', 'check_password'));
/** * If defaults contain null values, previous values are reused * @link http://pear.php.net/bugs/bug.php?id=20295 */ public function testBug20295() { $form = new HTML_QuickForm2('repeat-bug'); $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('buggy' => array('name' => array(1 => 'First', 2 => 'Second'), 'extra' => array(1 => 'Has extra', 2 => null))))); $group = new HTML_QuickForm2_Container_Group('buggy'); $group->addText('name'); $group->addText('extra'); $repeat = $form->addRepeat(null, array('id' => 'buggy-repeat'), array('prototype' => $group)); $value = $repeat->getValue(); $this->assertEquals('', $value['buggy']['extra'][2]); }
$row = package::info((int) $_GET['id']); if (empty($row['name'])) { report_error('Illegal package id'); response_footer(); exit; } print_package_navigation($row['packageid'], $row['name'], '/package-edit.php?id=' . $row['packageid']); $sth = $dbh->query('SELECT id, name FROM categories ORDER BY name'); while ($cat_row = $sth->fetchRow(DB_FETCHMODE_ASSOC)) { $rows[$cat_row['id']] = $cat_row['name']; } $form = new HTML_QuickForm2('package-edit', 'post', array('action' => '/package-edit.php?id=' . $row['packageid'])); $form->removeAttribute('name'); $renderer = HTML_QuickForm2_Renderer::factory('default'); // Set defaults for the form elements $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('name' => htmlspecialchars($row['name']), 'license' => htmlspecialchars($row['license']), 'summary' => htmlspecialchars($row['summary']), 'description' => htmlspecialchars($row['description']), 'category' => (int) $row['categoryid'], 'homepage' => htmlspecialchars($row['homepage']), 'doc_link' => htmlspecialchars($row['doc_link']), 'bug_link' => htmlspecialchars($row['bug_link']), 'cvs_link' => htmlspecialchars($row['cvs_link']), 'unmaintained' => $row['unmaintained'] ? true : false, 'newpk_id' => (int) $row['newpk_id'], 'new_channel' => htmlspecialchars($row['new_channel']), 'new_package' => htmlspecialchars($row['new_package'])))); $form->addElement('text', 'name', array('maxlength' => "80", 'accesskey' => "c"))->setLabel('Pa<span class="accesskey">c</span>kage Name'); $form->addElement('text', 'license', array('maxlength' => "50", 'placeholder' => 'BSD'))->setLabel('License:'); $form->addElement('textarea', 'summary', array('cols' => "75", 'rows' => "7", 'maxlength' => "255"))->setLabel('Summary'); $form->addElement('textarea', 'description', array('cols' => "75", 'rows' => "12"))->setLabel('Description'); $form->addElement('select', 'category')->setLabel('Category:')->loadOptions($rows); $manager = new Tags_Manager(); $sl = $form->addElement('select', 'tags', array('multiple' => 'multiple'))->setLabel('Tags:')->loadOptions(array('' => '(none)') + $manager->getTags(false, true)); $sl->setValue(array_keys($manager->getTags($row['name'], true))); $form->addElement('text', 'homepage', array('maxlength' => 255, 'accesskey' => "O"))->setLabel('H<span class="accesskey">o</span>mepage:'); $form->addElement('text', 'doc_link', array('maxlength' => 255, 'placeholder' => 'http://example.com/manual'))->setLabel('Documentation URI:'); $form->addElement('url', 'bug_link', array('maxlength' => 255, 'placeholder' => 'http://example.com/bugs'))->setLabel('Bug Tracker URI:'); $form->addElement('url', 'cvs_link', array('maxlength' => 255, 'placeholder' => 'http://example.com/svn/trunk'))->setLabel('Web version control URI'); $form->addElement('checkbox', 'unmaintained')->setLabel('Is this package unmaintained ?'); $packages = package::listAllwithReleases(); $rows = array(0 => '');
<?php // in real application the password check will a bit be different, of course function check_password($password) { return $password == 'qwerty'; } // // Form setup // require_once 'HTML/QuickForm2.php'; require_once 'HTML/QuickForm2/Renderer.php'; $form = new HTML_QuickForm2('basicRules'); // for file upload to work $form->setAttribute('enctype', 'multipart/form-data'); // data source with default values: $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('testUsername' => 'luser', 'friends' => array('luser123', 'gangsta1998')))); // override whatever value was submitted $form->addElement('hidden', 'MAX_FILE_SIZE')->setValue('102400'); // // Simple fields validation, rule chaining // $fsAuth = $form->addElement('fieldset')->setLabel('Auth credentials'); $username = $fsAuth->addElement('text', 'testUsername', array('style' => 'width: 200px;'))->setLabel('Username (letters only):'); $email = $fsAuth->addElement('text', 'testEmail', array('style' => 'width: 200px'))->setLabel('Email:'); $fsPasswords = $fsAuth->addElement('fieldset')->setLabel('Supply password only if you want to change it'); $oldPassword = $fsPasswords->addElement('password', 'oldPassword', array('style' => 'width: 200px;'))->setLabel('Old password (<i>qwerty</i>):'); $newPassword = $fsPasswords->addElement('password', 'newPassword', array('style' => 'width: 200px;'))->setLabel('New password (min 6 chars):'); $repPassword = $fsPasswords->addElement('password', 'newPasswordRepeat', array('style' => 'width: 200px;'))->setLabel('Repeat new password:'******'required', 'Username is required', null, HTML_QuickForm2_Rule::ONBLUR_CLIENT_SERVER); $username->addRule('regex', 'Username should contain only letters', '/^[a-zA-Z]+$/', HTML_QuickForm2_Rule::ONBLUR_CLIENT_SERVER); $email->addRule('email', 'Email address is invalid', null, HTML_QuickForm2_Rule::ONBLUR_CLIENT_SERVER);
/** * 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()); }
/** * correct handles the corrections of the protocol * * @param int $pid entry-id for protocol * @return string html of the correction page */ private function correct($pid) { // pagecaption $this->tpl->assign('pagecaption', parent::lang('class.ProtocolView#page#caption#correct')); // get protocol object $protocol = new Protocol($pid); $correctable = $protocol->get_correctable(false); // js tiny_mce $tmce = array('element' => 'protocol-0', 'css' => 'templates/protocols/tmce_' . $protocol->get_preset()->get_path() . '.css', 'transitem' => parent::lang('class.ProtocolView#new_entry#tmce#item'), 'transdecision' => parent::lang('class.ProtocolView#new_entry#tmce#decision')); // smarty $this->tpl->assign('tmce', $tmce); // check rights if (Rights::check_rights($pid, 'protocol', true) && (in_array($_SESSION['user']->get_id(), $correctable['correctors']) || $_SESSION['user']->get_userinfo('name') == $protocol->get_owner())) { // check owner if ($_SESSION['user']->get_userinfo('name') == $protocol->get_owner()) { // smarty $sPCo = new JudoIntranetSmarty(); // check action if ($this->get('action') == 'diff' && $this->get('uid') !== false) { // diff correction of $uid // get correction $correction = new ProtocolCorrection($protocol, $this->get('uid')); // clean protocols for diff $diffBase = html_entity_decode(preg_replace('/<.*>/U', '', $protocol->get_protocol())); $diffNew = html_entity_decode(preg_replace('/<.*>/U', '', $correction->get_protocol())); // smarty $sJsDL = new JudoIntranetSmarty(); // activate difflib js-files $this->tpl->assign('jsdifflib', true); // set values for difflib $difflib = array('protDiffBase' => 'protDiffBase-0', 'protDiffNew' => 'protDiffNew-0', 'protDiffOut' => 'diffOut', 'protDiffBaseCaption' => parent::lang('class.ProtocolView#correct#diff#baseCaption'), 'protDiffNewCaption' => parent::lang('class.ProtocolView#correct#diff#newCaption')); // add difflib values to js-template $sJsDL->assign('dl', $difflib); $this->add_jquery($sJsDL->fetch('smarty.js-jsdifflib.tpl')); // add diffOut to template $sPCo->assign('diffOut', 'diffOut'); // build form $form = new HTML_QuickForm2('diffCorrection', 'post', array('name' => 'diffCorrection', 'action' => 'protocol.php?id=correct&pid=' . $pid . '&action=diff&uid=' . $this->get('uid'))); $datasource = array('protocol' => $protocol->get_protocol(), 'protDiffBase' => $diffBase, 'protDiffNew' => $diffNew); // add datasource $form->addDataSource(new HTML_QuickForm2_DataSource_Array($datasource)); // renderer $renderer = HTML_QuickForm2_Renderer::factory('default'); $renderer->setOption('required_note', parent::lang('class.ProtocolView#entry#form#requiredNote')); // elements // protocol text $protocolTA = $form->addElement('textarea', 'protocol'); $protocolTA->setLabel(parent::lang('class.ProtocolView#entry#form#protocol') . ':'); $protocolTA->addRule('regex', parent::lang('class.ProtocolView#entry#rule#regexp.allowedChars') . ' [' . $_SESSION['GC']->get_config('textarea.desc') . ']', $_SESSION['GC']->get_config('textarea.regexp')); // checkbox to mark correction as finished $finished = $form->addElement('checkbox', 'finished'); $finished->setLabel(parent::lang('class.ProtocolView#entry#form#finished') . ':'); // hidden textareas for texts to diff $protocolBase = $form->addElement('textarea', 'protDiffBase'); $protocolNew = $form->addElement('textarea', 'protDiffNew'); // submit-button $form->addElement('submit', 'submit', array('value' => parent::lang('class.ProtocolView#entry#form#submitButton'))); // add form to template $sPCo->assign('c', true); $sPCo->assign('form', $form->render($renderer)); // validate if ($form->validate()) { // get form data $data = $form->getValue(); // check finished if (!isset($data['finished'])) { $data['finished'] = 0; } $correctionUpdate = array('finished' => $data['finished']); $protocolUpdate = array('protocol' => $data['protocol']); // update $protocol->update($protocolUpdate); $correction->update($correctionUpdate); $protocol->writeDb('update'); $correction->writeDb('update'); // message $message = array('message' => parent::lang('class.ProtocolView#correct#message#corrected'), 'href' => 'protocol.php?id=correct&pid=' . $pid . '&action=diff&uid=' . $this->get('uid'), 'title' => parent::lang('class.ProtocolView#correct#message#back'), 'text' => parent::lang('class.ProtocolView#correct#message#back')); // assign to template $sPCo->assign('c', false); $sPCo->assign('message', $message); } } else { // list all corrections // get corrections $corrections = ProtocolCorrection::listCorrections($pid); // put information together $list = array(); $user = new User(); foreach ($corrections as $correction) { // change user $user->change_user($correction['uid'], false, 'id'); // fill list $img = false; if ($correction['finished'] == 1) { $img = array('src' => 'img/done.png', 'alt' => parent::lang('class.ProtocolView#correct#difflist#imgDone'), 'title' => parent::lang('class.ProtocolView#correct#difflist#imgDone')); } $list[] = array('href' => 'protocol.php?id=correct&pid=' . $pid . '&action=diff&uid=' . $correction['uid'], 'title' => parent::lang('class.ProtocolView#correct#difflist#correctedBy') . ': ' . $user->get_userinfo('name'), 'text' => $user->get_userinfo('name') . ' (' . date('d.m.Y', strtotime($correction['modified'])) . ')', 'img' => $img); } // smarty $sPCo->assign('caption', parent::lang('class.ProtocolView#correct#difflist#caption')); $sPCo->assign('list', $list); } // return return $sPCo->fetch('smarty.protocolcorrection.owner.tpl'); } else { // get ProtocolCorretion object $correction = new ProtocolCorrection($protocol); // formular $form = new HTML_QuickForm2('correctProtocol', 'post', array('name' => 'correctProtocol', 'action' => 'protocol.php?id=correct&pid=' . $pid)); $datasource = array('protocol' => $correction->get_protocol()); // add datasource $form->addDataSource(new HTML_QuickForm2_DataSource_Array($datasource)); // renderer $renderer = HTML_QuickForm2_Renderer::factory('default'); $renderer->setOption('required_note', parent::lang('class.ProtocolView#entry#form#requiredNote')); // elements // protocol text $protocolTA = $form->addElement('textarea', 'protocol'); $protocolTA->setLabel(parent::lang('class.ProtocolView#entry#form#protocol') . ':'); $protocolTA->addRule('regex', parent::lang('class.ProtocolView#entry#rule#regexp.allowedChars') . ' [' . $_SESSION['GC']->get_config('textarea.desc') . ']', $_SESSION['GC']->get_config('textarea.regexp')); // submit-button $form->addElement('submit', 'submit', array('value' => parent::lang('class.ProtocolView#entry#form#submitButton'))); // validate if ($form->validate()) { // get form data $data = $form->getValue(); $correctionUpdate = array('protocol' => $data['protocol'], 'modified' => date('U'), 'pid' => $pid); // update protocol $correction->update($correctionUpdate); // write to db $action = 'new'; if (ProtocolCorrection::hasCorrected($pid) === true) { $action = 'update'; } $correction->writeDb($action); return parent::lang('class.ProtocolView#correct#message#done'); } else { return $form->render($renderer); } } } else { // error $errno = $GLOBALS['Error']->error_raised('NotAuthorized', 'entry:' . $this->get('id'), $this->get('id')); $GLOBALS['Error']->handle_error($errno); return $GLOBALS['Error']->to_html($errno); } }
<? include('installfooter.php'); ob_flush(); exit(0); } if(intval($_GET['page'])==0) { //include('../lib/recaptchalib.php'); //$recaptchaurl = recaptcha_get_signup_url (null,"FlexCP"); $form = new HTML_QuickForm2('frmInstall'); $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array( 'txtSiteURL' => 'http://'.$_SERVER['HTTP_HOST'].'/', 'txtSitePath' => dirname(dirname(__FILE__)).'/', 'txtAdminName' => 'Sysop', 'txtSQLHost' => 'localhost', 'txtSQLPrefix' => 'atbbs_', ))); $fsMain = $form->addElement('fieldset')->setLabel('Main ATBBS Configuration'); $sitename = $fsMain->addElement('text','txtSiteName', array(),array('label'=>'BBS\'s Name:')); $siteurl = $fsMain->addElement('text','txtSiteURL', array(),array('label'=>'Site URL:')); $sitepath = $fsMain->addElement('text','txtSitePath', array(),array('label'=>'Full path to site folder:')); $siteemail = $fsMain->addElement('text','txtSiteEmail', array(),array('label'=>'Email shown in automails, in the From: header:')); $siteadminname = $fsMain->addElement('text','txtAdminName', array(),array('label'=>'Used in place of Anonymous when an admin posts:')); $sitename->addRule('required','Field required.'); $siteurl->addRule('required','Field required.'); $sitepath->addRule('required','Field required.'); $siteemail->addRule('required','Field required.');
/** * edit edits the entry * * @return string html-string */ private function edit() { // smarty-templates $sD = new JudoIntranetSmarty(); // check rights if (Rights::check_rights($this->get('cid'), 'calendar')) { // check cid and pid given if ($this->get('cid') !== false && $this->get('pid') !== false) { // check cid and pid exists if (Calendar::check_id($this->get('cid')) && Preset::check_preset($this->get('pid'), 'calendar')) { // pagecaption $this->tpl->assign('pagecaption', parent::lang('class.AnnouncementView#page#caption#edit')); // prepare return $return = ''; // get preset $preset = new Preset($this->get('pid'), 'calendar', $this->get('cid')); // get fields $fields = $preset->get_fields(); // formular $form = new HTML_QuickForm2('edit_announcement', 'post', array('name' => 'edit_announcement', 'action' => 'announcement.php?id=edit&cid=' . $this->get('cid') . '&pid=' . $this->get('pid'))); // values $datasource = array(); foreach ($fields as $field) { // read values $field->read_value(); // check type if ($field->get_type() == 'text') { // check defaults $datasource['calendar-' . $field->get_id()]['manual'] = ''; $datasource['calendar-' . $field->get_id()]['defaults'] = 0; if ($field->get_value() == '') { $datasource['calendar-' . $field->get_id()]['defaults'] = 'd' . $field->get_defaults(); } else { $datasource['calendar-' . $field->get_id()]['manual'] = $field->get_value(); } } elseif ($field->get_type() == 'dbhierselect') { // explode value list($v_first, $v_second) = explode('|', $field->get_value(), 2); // set values $datasource['calendar-' . $field->get_id()][0] = $v_first; $datasource['calendar-' . $field->get_id()][1] = $v_second; } elseif ($field->get_type() == 'dbselect') { // check multiple if (strpos($field->get_value(), '|') !== false) { // separate value $values = explode('|', $field->get_value()); foreach ($values as $i => $value) { $datasource['calendar-' . $field->get_id()][$i] = $value; } } else { $datasource['calendar-' . $field->get_id()] = $field->get_value(); } } else { $datasource['calendar-' . $field->get_id()] = $field->get_value(); } } $form->addDataSource(new HTML_QuickForm2_DataSource_Array($datasource)); // renderer $renderer = HTML_QuickForm2_Renderer::factory('default'); $renderer->setOption('required_note', parent::lang('class.AnnouncementView#entry#form#requiredNote')); // generate field-quickform and add to form foreach ($fields as $field) { // generate quickform $field_id = $field->read_quickform(array(), true); // check $field_id if ($field_id != '' && $field->get_type() == 'date') { // smarty $sD->assign('elementid', $field_id . '-0'); $sD->assign('dateFormat', 'yy-mm-dd'); $sD->assign('dateValue', $field->get_value()); $this->add_jquery($sD->fetch('smarty.js-datepicker.tpl')); } // add to form $form->appendChild($field->get_quickform()); } // submit-button $form->addSubmit('submit', array('value' => parent::lang('class.AnnouncementView#edit#form#submitButton'))); // validate if ($form->validate()) { // get calendar $calendar = new Calendar($this->get('cid')); // prepare marker-array $announcement = array('version' => date('dmy')); // get data $data = $form->getValue(); // insert values foreach ($fields as $field) { // values to db $field->value($data[$field->get_table() . '-' . $field->get_id()]); $field->write_db('update'); } // add calendar-fields to array $calendar->add_marks($announcement); // add field-names and -values to array $preset->add_marks($announcement); // get field name and value $values = array(); foreach ($fields as $field) { $values[] = $field->value_to_html(); } // smarty $sAe = new JudoIntranetSmarty(); $sAe->assign('a', $announcement); for ($i = 0; $i < count($values); $i++) { if (preg_match('/\\{\\$a\\..*\\}/U', $values[$i]['value'])) { $values[$i]['value'] = $sAe->fetch('string:' . $values[$i]['value']); } } $sAe->assign('v', $values); return $sAe->fetch('smarty.announcement.edit.tpl'); } else { return $form->render($renderer); } } else { // error $errno = $GLOBALS['Error']->error_raised('WrongParams', 'entry:cid_or_pid', 'cid_or_pid'); $GLOBALS['Error']->handle_error($errno); return $GLOBALS['Error']->to_html($errno); } } else { // error $errno = $GLOBALS['Error']->error_raised('MissingParams', 'entry:cid_or_pid', 'cid_or_pid'); $GLOBALS['Error']->handle_error($errno); return $GLOBALS['Error']->to_html($errno); } } else { // error $errno = $GLOBALS['Error']->error_raised('NotAuthorized', 'entry:' . $this->get('id'), $this->get('id')); $GLOBALS['Error']->handle_error($errno); return $GLOBALS['Error']->to_html($errno); } }
/** * 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'); $el = $form->appendChild(new HTML_QuickForm2_ElementImpl('foo')); $el->setValue('not empty'); $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('foo' => null))); $this->assertNull($el->getValue()); }
} readfile($filename); ?> </style> <title>HTML_QuickForm2 basic elements example</title> </head> <body> <?php $options = array('a' => 'Letter A', 'b' => 'Letter B', 'c' => 'Letter C', 'd' => 'Letter D', 'e' => 'Letter E', 'f' => 'Letter F'); $main = array("Pop", "Rock", "Classical"); $secondary = array(array(0 => "Belle & Sebastian", 1 => "Elliot Smith", 2 => "Beck"), array(3 => "Noir Desir", 4 => "Violent Femmes"), array(5 => "Wagner", 6 => "Mozart", 7 => "Beethoven")); require_once 'HTML/QuickForm2.php'; require_once 'HTML/QuickForm2/Renderer.php'; $form = new HTML_QuickForm2('elements'); // data source with default values: $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('textTest' => 'Some text', 'areaTest' => "Some text\non multiple lines", 'userTest' => 'luser', 'selSingleTest' => 'f', 'selMultipleTest' => array('b', 'c'), 'boxTest' => '1', 'radioTest' => '2', 'testDate' => time(), 'testHierselect' => array(2, 5)))); // text input elements $fsText = $form->addElement('fieldset')->setLabel('Text boxes'); $fsText->addElement('text', 'textTest', array('style' => 'width: 300px;'), array('label' => 'Test Text:')); $fsText->addElement('password', 'pwdTest', array('style' => 'width: 300px;'), array('label' => 'Test Password:'******'textarea', 'areaTest', array('style' => 'width: 300px;', 'cols' => 50, 'rows' => 7), array('label' => 'Test Textarea:')); $fsNested = $form->addElement('fieldset')->setLabel('Nested fieldset'); $fsNested->addElement('text', 'userTest', array('style' => 'width: 200px'), array('label' => 'Username:'******'password', 'passTest', array('style' => 'width: 200px'), array('label' => 'Password:'******'fieldset')->setLabel('Selects'); $fsSelect->addElement('select', 'selSingleTest', null, array('options' => $options, 'label' => 'Single select:')); $fsSelect->addElement('select', 'selMultipleTest', array('multiple' => 'multiple', 'size' => 4), array('options' => $options, 'label' => 'Multiple select:')); // checkboxes and radios
/** * 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'); $date = $form->addDate('aDate', null, array('format' => 'Ymd'))->setValue('today'); $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('aDate' => null))); $this->assertNull($date->getValue()); }
/** * 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'); $box = $form->addCheckbox('box', array('value' => 'yep', 'checked' => 'checked')); // data source searching should stop on finding this null $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('box' => null))); $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('box' => 'yep'))); $this->assertNull($box->getValue()); }