/** * Allow to properly set values for checkboxes named like 'box[]' * @see http://pear.php.net/bugs/bug.php?id=16806 */ public function testRequest16806() { $formPost = new HTML_QuickForm2('request16806', 'post', null, false); $box1 = $formPost->addElement('checkbox', 'vegetable[]', array('value' => 1), array('label' => 'carrot')); $box2 = $formPost->addElement('checkbox', 'vegetable[]', array('value' => 2), array('label' => 'pea')); $box3 = $formPost->addElement('checkbox', 'vegetable[]', array('value' => 3), array('label' => 'bean')); $this->assertEquals('checked', $box1->getAttribute('checked')); $this->assertNotEquals('checked', $box2->getAttribute('checked')); $this->assertEquals('checked', $box3->getAttribute('checked')); }
/** * Wrapper around HTML_QuickForm2_Container's addElement() * * @param string|HTML_QuickForm2_Node Either type name (treated * case-insensitively) or an element instance * @param mixed Element name * @param mixed Element attributes * @param array Element-specific data * @return HTML_QuickForm2_Node Added element * @throws HTML_QuickForm2_InvalidArgumentException * @throws HTML_QuickForm2_NotFoundException */ public function addElement($elementOrType, $name = null, $attributes = null, array $data = array()) { if ($name != 'submit') { $this->a_formElements[] = $name; } return parent::addElement($elementOrType, $name, $attributes, $data); }
public function addElement($elementOrType, $name = null, $attributes = null, array $data = array()) { $ret = parent::addElement($elementOrType, $name, $attributes, $data); if ($ret instanceof HTML_QuickForm2_Element_InputFile) { $this->setAttribute('enctype', 'multipart/form-data'); } return $ret; }
/** * Wrapper around populateForm() ensuring that it is only called once */ public final function populateFormOnce() { if (!$this->_formPopulated) { if (!empty($this->controller) && $this->controller->propagateId()) { $this->form->addElement('hidden', HTML_QuickForm2_Controller::KEY_ID, array('id' => HTML_QuickForm2_Controller::KEY_ID))->setValue($this->controller->getId()); } $this->populateForm(); $this->_formPopulated = true; } }
public function testPerform() { $formOne = new HTML_QuickForm2('formOne'); $formOne->addElement('text', 'foo')->setValue('foo value'); $pageOne = $this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array($formOne)); $formTwo = new HTML_QuickForm2('formTwo'); $formTwo->addElement('text', 'bar')->setValue('bar value'); $pageTwo = $this->getMock('HTML_QuickForm2_Controller_Page', array('populateForm'), array($formTwo)); $mockJump = $this->getMock('HTML_QuickForm2_Controller_Action', array('perform')); $mockJump->expects($this->exactly(2))->method('perform')->will($this->returnValue('jump to foo')); $pageOne->addHandler('jump', $mockJump); $controller = new HTML_QuickForm2_Controller('testBackAction'); $controller->addPage($pageOne); $controller->addPage($pageTwo); $this->assertEquals('jump to foo', $pageTwo->handle('back')); $this->assertEquals(array(), $controller->getSessionContainer()->getValues('formOne')); $this->assertContains('bar value', $controller->getSessionContainer()->getValues('formTwo')); $this->assertEquals('jump to foo', $pageOne->handle('back')); $this->assertContains('foo value', $controller->getSessionContainer()->getValues('formOne')); }
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; }
// 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. */ // Remove 'space' first and last in all parameters. $form->addRecursiveFilter('trim');
$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'); $form->addElement('text', 'new_row[costo]')->setLabel('Costo:')->addRule('required', 'Valor requerido'); $form->addElement('file', 'file')->setLabel('Archivo PDF:')->addRule('mimetype', 'Valor requerido', 'application/pdf'); $form->addElement('button', 'btnSubmit', array('type' => 'submit', 'value' => 'Guardar', 'class' => 'btn btn-primary'))->setContent('Guardar'); // renderer fixes require_once 'HTML/QuickForm2/Renderer.php';
/** * delete deletes the given entry * * @param int $cid entry-id for calendar * @return string html-string */ private function delete($cid) { // pagecaption $this->tpl->assign('pagecaption', parent::lang('class.CalendarView#page#caption#delete') . ": {$cid}"); // check rights if (Rights::check_rights($cid, 'calendar')) { // prepare return $output = ''; // smarty-templates $sConfirmation = new JudoIntranetSmarty(); $form = new HTML_QuickForm2('confirm', 'post', array('name' => 'confirm', 'action' => 'calendar.php?id=delete&cid=' . $this->get('cid'))); // add button $form->addElement('submit', 'yes', array('value' => parent::lang('class.CalendarView#delete#form#yes'))); // smarty-link $link = array('params' => '', 'href' => 'calendar.php?id=listall', 'title' => parent::lang('class.CalendarView#delete#title#cancel'), 'content' => parent::lang('class.CalendarView#delete#form#cancel')); $sConfirmation->assign('link', $link); $sConfirmation->assign('spanparams', 'id="cancel"'); $sConfirmation->assign('message', parent::lang('class.CalendarView#delete#message#confirm')); $sConfirmation->assign('form', $form); // validate if ($form->validate()) { // get calendar-object $calendar = new Calendar($cid); // disable entry $calendar->update(array('valid' => 0)); // smarty $sConfirmation->assign('message', parent::lang('class.CalendarView#delete#message#done')); $sConfirmation->assign('form', ''); // write entry try { $calendar->write_db('update'); } catch (Exception $e) { $GLOBALS['Error']->handle_error($e); return $GLOBALS['Error']->to_html($e); } } // smarty return return $sConfirmation->fetch('smarty.confirmation.tpl'); } 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); } }
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:')); $arskursElev->addRule('maxlength', 'Ange årskursen med siffror.', 2); $skolaElev = $fsElev->addElement('text', 'skolaElev', array('style' => 'width: 300px;'), array('label' => 'Ordinarie skola:'));
/** * 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; }
} else { $table = new HTML_Table('style="width: 90%"'); $table->setCaption('Karma levels for ' . htmlspecialchars($handle), 'style="background-color: #CCCCCC;"'); $table->addRow(array("Level", "Added by", "Added at", "Remove"), null, 'th'); foreach ($user_karma as $item) { $remove = sprintf("karma.php?action=remove&handle=%s&level=%s", htmlspecialchars($handle), htmlspecialchars($item['level'])); $table->addRow(array(htmlspecialchars($item['level']), htmlspecialchars($item['granted_by']), htmlspecialchars($item['granted_at']), make_link($remove, make_image("delete.gif"), false, 'onclick="javascript:return confirm(\'Do you really want to remove the karma level ' . htmlspecialchars($item['level']) . '?\');"'))); } echo $table->toHTML(); } echo "<br /><br />"; $table = new HTML_Table('style="width: 100%"'); $table->setCaption("Grant karma to " . htmlspecialchars($handle), 'style="background-color: #CCCCCC;"'); $form = new HTML_QuickForm2('karma_grant', 'post', array('action' => 'karma.php?action=grant')); $form->removeAttribute('name'); $form->addElement('text', 'level')->setLabel('Level: '); $form->addElement('hidden', 'handle')->setValue(htmlspecialchars($handle)); $form->addElement('submit', 'submit')->setLabel('Submit Changes'); $csrf_token_value = create_csrf_token($csrf_token_name); $form->addElement('hidden', $csrf_token_name)->setValue($csrf_token_value); $table->addRow(array((string) $form)); echo $table->toHTML(); } echo "<p> </p><hr />"; $table = new HTML_Table('style="width: 90%"'); $table->setCaption("Karma Statistics", 'style="background-color: #CCCCCC;"'); if (!empty($_GET['a']) && $_GET['a'] == "details" && !empty($_GET['level'])) { $table->addRow(array('Handle', 'Granted'), null, 'th'); foreach ($karma->getUsers($_GET['level']) as $user) { $detail = sprintf("Granted by <a href=\"/user/%s\">%s</a> on %s", htmlspecialchars($user['granted_by']), htmlspecialchars($user['granted_by']), htmlspecialchars($user['granted_at'])); $table->addRow(array(make_link("/user/" . htmlspecialchars($user['user']), htmlspecialchars($user['user'])), $detail));
# add_page.php - Script 9.15 // This page both displays and handles the "add a page" form. // Need the utilities file: require 'includes/utilities.inc.php'; // Redirect if the user doesn't have permission: if (!$user->canCreatePage()) { header("Location:index.php"); exit; } // Create a new form: set_include_path(get_include_path() . PATH_SEPARATOR . '/usr/local/pear/share/pear/'); require 'HTML/QuickForm2.php'; $form = new HTML_QuickForm2('addPageForm'); // Add the title field: $title = $form->addElement('text', 'title'); $title->setLabel('Page Title'); $title->addFilter('strip_tags'); $title->addRule('required', 'Please enter a page title.'); // Add the content field: $content = $form->addElement('textarea', 'content'); $content->setLabel('Page Content'); $content->addFilter('trim'); $content->addRule('required', 'Please enter the page content.'); // Add the submit button: $submit = $form->addElement('submit', 'submit', array('value' => 'Add This Page')); // Check for a form submission: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Handle the form submission // Validate the form data: if ($form->validate()) {
$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 {$this_table} where {$this_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($this_action); $form->addElement('hidden', 'params')->setValue($form_params); $form->addElement('text', 'new_row[urna_nombre]', array('autofocus' => 'autofocus', 'maxlength' => '256'))->setLabel('Nombre de la Urna:')->addRule('required', 'Valor requerido'); $form->addElement('button', 'btnSubmit', array('type' => 'submit', 'value' => 'Guardar', 'class' => 'btn btn-lg btn-primary'))->setContent('Guardar'); // validaciones //$form->addRule('each', 'Phones should be numeric', $form->createRule('regex', '', '/^\\d+([ -]\\d+)*$/')); // defaults $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('new_row' => array('fecha_atencion_inicial' => time())))); $form->addRecursiveFilter('trim'); require_once 'HTML/QuickForm2/Renderer.php'; require_once 'HTML/QuickForm2/JavascriptBuilder.php'; $renderer = HTML_QuickForm2_Renderer::factory('default'); $renderer->setJavascriptBuilder(new HTML_QuickForm2_JavascriptBuilder(null, __DIR__ . '/../lib/pear/data/HTML_QuickForm2/js')); $renderer->setOption(array('errors_prefix' => 'El formulario contiene errores:', 'required_note' => '<div><span class="required">*</span> denota campos requeridos</div>'));
?> </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 $fsCheck = $form->addElement('fieldset')->setLabel('Checkboxes and radios'); $fsCheck->addElement('checkbox', 'boxTest', null, array('content' => 'check me', 'label' => 'Test Checkbox:'));
/** * 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); } }
/** * delete deletes the given entry * * @param int $cid entry-id for calendar * @return string html-string */ private function delete() { // 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#delete')); // prepare return $return = ''; // smarty-templates $sConfirmation = new JudoIntranetSmarty(); $form = new HTML_QuickForm2('confirm', 'post', array('name' => 'confirm', 'action' => 'announcement.php?id=delete&cid=' . $this->get('cid') . '&pid=' . $this->get('pid'))); // add button $form->addElement('submit', 'yes', array('value' => parent::lang('class.AnnouncementView#delete#form#yes'))); // smarty-link $link = array('params' => '', 'href' => 'calendar.php?id=listall', 'title' => parent::lang('class.AnnouncementView#delete#title#cancel'), 'content' => parent::lang('class.AnnouncementView#delete#form#cancel')); $sConfirmation->assign('link', $link); $sConfirmation->assign('spanparams', 'id="cancel"'); $sConfirmation->assign('message', parent::lang('class.AnnouncementView#delete#message#confirm')); $sConfirmation->assign('form', $form); // validate if ($form->validate()) { // get calendar-object $calendar = new Calendar($this->get('cid')); // get preset $preset = new Preset($this->get('pid'), 'calendar', $this->get('cid')); // get fields $fields = $preset->get_fields(); // delete values of the fields if (Calendar::check_ann_value($calendar->get_id(), $calendar->get_preset_id()) === true) { foreach ($fields as $field) { // delete value $field->delete_value(); } } // set preset to 0 $calendar->update(array('preset_id' => 0)); // smarty $sConfirmation->assign('message', parent::lang('class.AnnouncementView#delete#message#done')); $sConfirmation->assign('form', ''); // write entry try { $calendar->write_db('update'); } catch (Exception $e) { $GLOBALS['Error']->handle_error($e); $output = $GLOBALS['Error']->to_html($e); } } // smarty return return $sConfirmation->fetch('smarty.confirmation.tpl'); } 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); } }
<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();
} } } } } /* * 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? $sendPassword = $fsAccount->addElement('checkbox', 'send', array('value' => '1'))->setContent('Skicka lösenordet med mejl till användaren');
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 //$form->addRule('each', 'Phones should be numeric', $form->createRule('regex', '', '/^\\d+([ -]\\d+)*$/')); // defaults $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('new_row' => array('fecha_atencion_inicial' => time(), 'fecha_ingreso_institucion' => time()))));
// 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')); // this behaves exactly as it reads: either "password" and "password repeat" // are empty or they should be equal, password should be no less than 6 chars
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); } } $renderer = HTML_QuickForm2_Renderer::factory('default');
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 => ''); foreach ($packages as $id => $info) {
$territorios_select[$row['k']] = $row['v']; } $five_select[''] = '--Seleccione--'; $five_select['5'] = '5'; $five_select['4'] = '4'; $five_select['3'] = '3'; $five_select['2'] = '2'; $five_select['1'] = '1'; $form_params = params_encode($params); $form_update = false; if (isset($record_id)) { $form_update = true; } $form = new HTML_QuickForm2('form', 'post', array('role' => 'form')); // elements $form->addElement('hidden', 'action')->setValue($params['action']); $form->addElement('hidden', 'params')->setValue($form_params); if ($form_update) { $form->addElement('text', 'nota_id', array('disabled' => 'disabled'), array('label' => 'Nota Id'))->setValue($record_id); } $form->addElement('select', 'new_row[medio_id]', array('autofocus' => 'autofocus'))->setLabel('Medio:')->loadOptions($medio_select)->addRule('required', 'Valor requerido'); $form->addElement('date', 'new_row[fecha]', array('class' => 'form-control-inline'), $date_options)->setLabel('Fecha:')->addRule('required', 'Valor requerido'); $form->addElement('hierselect', 'region')->setLabel('Pais:')->setSeparator(array('Provincia:', 'Localidad'))->loadOptions(array($pais_select, $pcia_select, $loc_select)); /* $form->addElement('select', 'new_row[territorio_id]') ->setLabel('Territorio:') ->loadOptions($territorio_select) ->addRule('required', 'Valor requerido') ; */ $form->addElement('text', 'new_row[titulo]')->setLabel('Título:')->addRule('required', 'Valor requerido');
} 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.'); $siteadminname->addRule('required','Field required.'); $fsSQL = $form->addElement('fieldset')->setLabel('Database configuration');
nombre, relevancia, tipo, web, carga_fecha from medio where 1 = 1 END; $sql_data = array(); $zona_select = array('' => '--Todas--', 'Norte' => 'Norte', 'Centro' => 'Centro', 'Buenos Aires' => 'Buenos Aires', 'Sur' => 'Sur', 'Nacional y Agencias' => 'Nacional y Agencias'); $pcia_select = array(null => '--Todas--', 'N/A' => 'Nacional y Agencias', 'Chaco' => 'Chaco', 'Jujuy' => 'Jujuy', 'Corriente' => 'Corrientes', 'Misiones' => 'Misiones', 'Salta' => 'Salta', 'Catamarca' => 'Catamarca', 'Formosa' => 'Formosa', 'Santiago del Estero' => 'Santiago del Estero', 'Tucuman' => 'Tucuman', 'Santa Fe' => 'Santa Fe', 'Cordoba' => 'Cordoba', 'Entre Rios' => 'Entre Rios', 'San Juan' => 'San Juan', 'Mendoza' => 'Mendoza', 'San Luis' => 'San Luis', 'La Pampa' => 'La Pampa', 'La Rioja' => 'La Rioja', 'Buenos Aires' => 'Buenos Aires', 'Rio Negro' => 'Rio Negro', 'Neuquen' => 'Neuquen', 'Chubut' => 'Chubut', 'Santa Cruz' => 'Santa Cruz', 'Tierra del Fuego' => 'Tierra del Fuego'); $form = new HTML_QuickForm2('search', 'get'); // elements $form->addElement('hidden', 'action')->setValue($action); $form->addElement('select', 'zona', $campo_corto)->setLabel('Zona:')->loadOptions($zona_select); $form->addElement('select', 'provincia', $campo_medio)->setLabel('Provincia:')->loadOptions($pcia_select); $submit = $form->addSubmit('btnSubmit', array('value' => 'Buscar'))->addClass(array('btn', 'btn-primary')); //////////////////////////////////////////////////////////// // renderer fixes function renderSubmit($renderer, $submit) { return '<div class="form-actions">' . $submit . '</div>'; } require_once 'HTML/QuickForm2/Renderer.php'; $renderer = HTML_QuickForm2_Renderer::factory('callback'); $renderer->setCallbackForId($submit->getId(), 'renderSubmit'); $renderer->setOption(array('errors_prefix' => 'El formulario contiene errores:', 'required_note' => '<span class="required">*</span> denota campos requeridos')); //////////////////////////////////////////////////////////// include 'header.php';
require_once 'share/data_display.php'; include 'share/form_common.php'; require_once 'HTML/QuickForm2.php'; $sql = <<<END select * from region where 1 = 1 END; $sql_data = array(); $form = new HTML_QuickForm2('search', 'get', array('class' => 'noprint')); // elements $form->addElement('hidden', 'action')->setValue($action); $form->addElement('text', 'localidad')->setLabel('Localidad:'); $form->addElement('button', 'btnSubmit', array('type' => 'submit', 'value' => 'Buscar', 'class' => 'btn btn-primary'))->setContent('Buscar'); include 'header.php'; echo '<div class="page-header">'; echo '<h1>Lista de regiones <small>Ordenado por pais, provincia, localidad</small></h1>'; echo '<div class="noprint">'; echo '<a href="?action=region_insert">Cargar Región</a>'; echo '</div>'; echo '</div>'; echo $form; // procesamos la busqueda $sql_where = ''; if (isset($_GET['btnSubmit']) and $_GET['btnSubmit'] != '') { $sql_data = array(); if (!empty($_GET['localidad'])) {
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 {$this_table} where {$this_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($this_action); $form->addElement('hidden', 'params')->setValue($form_params); $form->addElement('select', 'new_row[urna_id]', array('autofocus' => 'autofocus'))->setLabel('Urna:')->loadOptions($urna_select)->addRule('required', 'Valor requerido'); $form->addElement('select', 'new_row[lista_id]')->setLabel('Lista:')->loadOptions($lista_select)->addRule('required', 'Valor requerido'); $form->addElement('text', 'new_row[votos_centro]', array('maxlength' => '3'))->setLabel('Votos Centro:')->addRule('required', 'Valor requerido'); $form->addElement('text', 'new_row[votos_claustro]', array('maxlength' => '3'))->setLabel('Votos Claustro:')->addRule('required', 'Valor requerido'); $form->addElement('button', 'btnSubmit', array('type' => 'submit', 'value' => 'Guardar', 'class' => 'btn btn-lg btn-primary'))->setContent('Guardar'); // validaciones //$form->addRule('each', 'Phones should be numeric', $form->createRule('regex', '', '/^\\d+([ -]\\d+)*$/')); // defaults $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('new_row' => array('fecha_atencion_inicial' => time())))); $form->addRecursiveFilter('trim'); require_once 'HTML/QuickForm2/Renderer.php'; require_once 'HTML/QuickForm2/JavascriptBuilder.php'; $renderer = HTML_QuickForm2_Renderer::factory('default'); $renderer->setJavascriptBuilder(new HTML_QuickForm2_JavascriptBuilder(null, __DIR__ . '/../lib/pear/data/HTML_QuickForm2/js'));
END; $zona_select = array('' => '--Todas--', 'Norte' => 'Norte', 'Centro' => 'Centro', 'Buenos Aires' => 'Buenos Aires', 'Sur' => 'Sur', 'Nacional y Agencias' => 'Nacional y Agencias'); $mencion_escala[''] = '--Todas--'; $mencion_escala['NSP'] = 'Nota sobre el programa (NSP)'; $mencion_escala['MP'] = 'Mención del programa (MP)'; $mencion_escala['TR'] = 'Tema relacionado (TR)'; $pcia_select = array(null => '--Todas--', 'N/A' => 'Nacional y Agencias', 'Chaco' => 'Chaco', 'Jujuy' => 'Jujuy', 'Corriente' => 'Corrientes', 'Misiones' => 'Misiones', 'Salta' => 'Salta', 'Catamarca' => 'Catamarca', 'Formosa' => 'Formosa', 'Santiago del Estero' => 'Santiago del Estero', 'Tucuman' => 'Tucuman', 'Santa Fe' => 'Santa Fe', 'Cordoba' => 'Cordoba', 'Entre Rios' => 'Entre Rios', 'San Juan' => 'San Juan', 'Mendoza' => 'Mendoza', 'San Luis' => 'San Luis', 'La Pampa' => 'La Pampa', 'La Rioja' => 'La Rioja', 'Buenos Aires' => 'Buenos Aires', 'Rio Negro' => 'Rio Negro', 'Neuquen' => 'Neuquen', 'Chubut' => 'Chubut', 'Santa Cruz' => 'Santa Cruz', 'Tierra del Fuego' => 'Tierra del Fuego'); $valoracion_select[''] = '--Seleccione--'; $valoracion_select['+1'] = 'Positiva (+1)'; $valoracion_select['0'] = 'Neutra (0)'; $valoracion_select['-1'] = 'Negativa (-1)'; $valoracion_select['-2'] = 'Denuncia (-2)'; //$form_params = params_encode($params); $form = new HTML_QuickForm2('search', 'get'); // elements $form->addElement('hidden', 'action')->setValue($action); $form->addElement('select', 'zona', $campo_corto)->setLabel('Zona:')->loadOptions($zona_select); $form->addElement('select', 'provincia', $campo_medio)->setLabel('Provincia:')->loadOptions($pcia_select); $form->addElement('text', 'medio', $campo_medio)->setLabel('Medio:'); $form->addElement('select', 'mencion')->setLabel('Mención:')->loadOptions($mencion_escala); $form->addElement('select', 'valoracion')->setLabel('Valoración:')->loadOptions($valoracion_select); $form->addElement('text', 'texto', $campo_largo)->setLabel('Texto:'); $form->addElement('date', 'fecha_carga_desde', $campo_corto, array('addEmptyOption' => true, 'emptyOptionText' => array('Y' => 'Anio:', 'M' => 'Mes:', 'd' => 'Dia:')))->setLabel('Fecha carga desde:'); $form->addElement('date', 'fecha_carga_hasta', $campo_corto, array('addEmptyOption' => true, 'emptyOptionText' => array('Y' => 'Anio:', 'M' => 'Mes:', 'd' => 'Dia:')))->setLabel('Fecha carga hasta:'); $submit = $form->addSubmit('btnSubmit', array('value' => 'Buscar'))->addClass(array('btn', 'btn-primary')); //////////////////////////////////////////////////////////// // renderer fixes function renderSubmit($renderer, $submit) { return '<div class="form-actions">' . $submit . '</div>'; }
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); // old password should be either left blank or be equal to 'qwerty' $oldPassword->addRule('empty', '', null, HTML_QuickForm2_Rule::ONBLUR_CLIENT_SERVER)->or_($oldPassword->createRule('callback', 'Wrong password', 'check_password'));