/** * Renvoit l'instance d'un formulaire * * Un formulaire est instancié, configuré puis renvoyé * * @param string $url URL pour l'attribut "action" du formulaire * @param string $nom Nom du formulaire * @return object */ function &instancierFormulaire($url = null, $nom = 'formulaire') { if (is_null($url)) { $url = $_SERVER['REQUEST_URI']; } require_once dirname(__FILE__) . '/../../dependencies/PEAR/HTML/QuickForm.php'; require_once dirname(__FILE__) . '/../../dependencies/PEAR/HTML/QuickForm/altselect.php'; $formulaire = new HTML_QuickForm($nom, 'post', $url); $formulaire->removeAttribute('name'); return $formulaire; }
<?php // no direct access defined('PARENT_FILE') or die('Restricted access'); if ($this->authorize()) { $menuBar = array('cancel' => '/ushop/tax/overview', 'save' => null); $this->content .= $this->makeToolbar($menuBar, 24); $menuBar = array(); $rows = $this->getResult('tax_code_id, tax_rate_id, tax_code, description', $ushop->db_name . 'tax_codes', null, array('where' => 'tax_code_id = ' . $this->registry->params['id'])); $form = new HTML_QuickForm('edit_tax_code', 'post', $_SERVER['REQUEST_URI']); // Remove name attribute for xhtml strict compliance. $form->removeAttribute('name'); $s = $form->createElement('select', 'tax_rate_id', 'Tax Rate:'); $opts[0] = 'Select One'; $tax_rates = $ushop->getTaxRates(true); foreach ($tax_rates as $rate) { $opts[$rate->tax_rate_id] = ucwords($rate->tax_rate); } $form->addElement('html', '<fieldset>'); $form->addElement('header', 'edit_tax_code', 'Edit Tax Code'); $form->addElement('text', 'tax_code', 'Tax Code:', array('size' => 2, 'maxlength' => 2, 'class' => 'inputbox')); $s->loadArray($opts); $form->addElement($s); $form->addElement('text', 'description', 'Description:', array('size' => 20, 'maxlength' => 20, 'class' => 'inputbox')); $form->addElement('html', '</fieldset>'); $form->addRule('description', 'Please enter a decription', 'required'); $form->addRule('tax_code', 'Please enter a tax code', 'required'); $form->addRule('tax_code', 'Tax codes have only letters', 'lettersonly'); if ($form->validate()) { $form->freeze(); $values = $form->process(array(&$this, 'formValues'), false);
/** * Remplit le layer de customisation des grids. * * @param object $tpl instanceof Template * @access private * @return void */ private function _customDisplay($tpl) { require_once 'HTML/QuickForm.php'; require_once 'HTML/QuickForm/Renderer/ArraySmarty.php'; require_once 'HTML/QuickForm/advmultiselect.php'; $renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl); $form = new HTML_QuickForm('gridCustomDisplay', 'post', $_SERVER['PHP_SELF']); $form->removeAttribute('name'); // XHTML compliance $defaultValues = array(); // Valeurs par defaut des champs du form $form->updateAttributes(array('onsubmit' => "return checkBeforeSubmit();")); //$form->updateAttributes(array('onsubmit' => '$(\'customDisplayUpdated\').value=1;')); $form->addElement('hidden', 'customDisplayUpdated', '0'); // Les plus souvent utilises $nbItemsArray = array(30 => 30, 50 => 50, 100 => 100, 150 => 150, 200 => 200, 300 => 300, 500 => 500); if ($this->paged) { $defaultItemPerPage = $this->itemPerPage; if (!in_array($defaultItemPerPage, $nbItemsArray)) { $nbItemsArray[$defaultItemPerPage] = $defaultItemPerPage; sort($nbItemsArray); } $form->addElement('select', 'customDisplayItemPerPage', _('Items number per page'), $nbItemsArray); // ToDo: MODIFIER en fction des saisies!! $defaultValues['customDisplayItemPerPage'] = $defaultItemPerPage; } $cols = array(); foreach ($this->columns as $colIndex => $column) { // Groupement de colonnes: toDo? // $column->groupCaption . ' ' . $column->title; if (!$column->enabled || $column->groupCount) { // On n'affiche que les column actives et continue; } // Pour la gestion des sous-grids, on nettoie l'entete $cols[$colIndex] = stripos($column->title, '</td><td>') !== false ? substr(str_replace('</td><td>', ', ', $column->title), 2, -2) : $column->title; } $labels = array(_('Columns') . ':', _('Available columns'), _('Columns to hide')); $elt = HTML_QuickForm::createElement('advmultiselect', 'customDisplayHiddenColumns', $labels, $cols, array('style' => 'width:100%;')); // Necessaire pour externaliser la tonne de js, si include js trouve $js = file_exists('JS_AdvMultiSelect.php') ? '' : '{javascript}'; $jsValidation = '<script type="text/javascript"> //<![CDATA[ function checkBeforeSubmit() { if ($(\'__customDisplayHiddenColumns\').options.length == 0) { alert("' . _("You can't hide all columns.") . '"); return false; } return true; } //]]> </script>'; $eltTemplate = $js . $jsValidation . ' <table{class}> <tr><th>{label_2}</th><th> </th><th>{label_3}</th></tr> <tr> <td valign="top">{unselected}</td> <td align="center">{add}{remove}</td> <td valign="top">{selected}</td> </tr> </table> '; $elt->setElementTemplate($eltTemplate); $form->addElement($elt); $form->addElement('submit', 'customDisplaySubmit', A_VALIDATE, 'onclick="this.form.customDisplayUpdated.value=1;"'); /*$form->addElement('button', 'customDisplaySetDefault', _('Default values'), 'onclick="fw.dom.selectOptionByValue($(\'customDisplayColumns\'), ' . JsTools::JSArray($nbItemsArray) . ');this.form.submit();"'); $(\'customDisplayUpdated\').value=1*/ $form->addElement('button', 'customDisplayCancel', A_CANCEL, 'onclick="fw.dom.toggleElement($(\'custom_display_layer\'));"'); $defaultValues['customDisplayHiddenColumns'] = $this->hiddenColumnsByUser; $form->setDefaults($defaultValues); // PATCH car advmultiselect buggé!! $elt->_values = $defaultValues['customDisplayHiddenColumns']; // end PATCH $form->accept($renderer); // affecte au form le renderer personnalise $tpl->assign('form', $renderer->toArray()); }
<?php require_once "common.inc.php"; require_once "HTML/QuickForm.php"; require_once "HTML/QuickForm/Renderer/Tableless.php"; $form = new HTML_QuickForm("", "post", "register.php", "", array("style" => "width: 30em;"), true); $form->removeAttribute("name"); addElements($form); addRules($form); $form->setRequiredNote(""); if ($form->isSubmitted() and $form->validate()) { $form->process("processForm"); displayThanks(); } else { displayPageHeader("Sign up for the book club!"); ?> <p>Thanks for choosing to join our book club.</p> <p>To register, please fill in your details below and click Send Details.</p> <p>Fields marked with an asterisk (*) are required.</p> <?php $renderer = new HTML_QuickForm_Renderer_Tableless(); $form->accept($renderer); echo $renderer->toHtml(); displayPageFooter(); } function addElements($form) { $form->addElement("text", "username", "Choose a username"); $password1 = $form->addElement("password", "password1", "Choose a password"); $password1->setValue(""); $password2 = $form->addElement("password", "password2", "Retype password");
/** * Remplit le layer de customisation des searchforms. * * @param object $tpl instanceof Template * @access private * @return void */ private function _customDisplay($tpl) { require_once 'HTML/QuickForm.php'; require_once 'HTML/QuickForm/Renderer/ArraySmarty.php'; require_once 'HTML/QuickForm/advmultiselect.php'; $renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl); $form = new HTML_QuickForm('CustomSearch', 'post', $_SERVER['PHP_SELF']); $form->removeAttribute('name'); // XHTML compliance $defaultValues = array(); // Valeurs par defaut des champs du form $form->updateAttributes(array('onsubmit' => "return checkBeforeSubmit();")); $form->addElement('hidden', 'customSearchUpdated', '0'); $criteria = array(); foreach ($this->_elementsToDisplay as $elementName => $type) { if ($type == 'blank' || substr($type, 0, 4) == 'date') { continue; } $criteria[$elementName] = $this->_form->getElement($elementName)->getLabel(); } $labels = array(_('criteria') . ':', _('Available criteria'), _('Criteria to hide')); $elt = HTML_QuickForm::createElement('advmultiselect', 'customSearchHiddenCriteria', $labels, $criteria, array('style' => 'width:100%;')); // Necessaire pour externaliser la tonne de js, si include js trouve $js = file_exists('JS_AdvMultiSelect.php') ? '' : '{javascript}'; $jsValidation = '<script type="text/javascript"> //<![CDATA[ function checkBeforeSubmit() { if ($(\'__customSearchHiddenCriteria\').options.length == 0) { alert("' . _("You can't hide all criteria.") . '"); return false; } return true; } //]]> </script>'; $eltTemplate = $js . $jsValidation . ' <table{class}> <tr><th>{label_2}</th><th> </th><th>{label_3}</th></tr> <tr> <td valign="top">{unselected}</td> <td align="center">{add}{remove}</td> <td valign="top">{selected}</td> </tr> </table> '; $elt->setElementTemplate($eltTemplate); $form->addElement($elt); $form->addElement('submit', 'customSearchSubmit', A_VALIDATE, 'onclick="this.form.customSearchUpdated.value=1;"'); $form->addElement('button', 'customSearchCancel', A_CANCEL, 'onclick="fw.dom.toggleElement($(\'custom_search_layer\'));"'); $defaultValues['customSearchHiddenCriteria'] = $this->hiddenCriteriaByUser; $form->setDefaults($defaultValues); // PATCH car advmultiselect buggé!! $elt->_values = $defaultValues['customSearchHiddenCriteria']; // end PATCH $form->accept($renderer); // affecte au form le renderer personnalise $tpl->assign('customSearchForm', $renderer->toArray()); }