/** * Stores the form values (and validation status) is session container * * @param bool Whether to store validation status */ public function storeValues($validate = true) { $this->populateFormOnce(); $container = $this->getController()->getSessionContainer(); $id = $this->form->getId(); $container->storeValues($id, (array) $this->form->getValue()); if ($validate) { $container->storeValidationStatus($id, $this->form->validate()); } return $container->getValidationStatus($id); }
$rcpriv=$fsCaptcha->addElement('text','txtCPrivate',array(),array('label'=>'reCaptcha Private Key (<a href="'.$recaptchaurl.'">Get One</a>):')); $mhpub=$fsCaptcha->addElement('text','txtMHPublic', array(),array('label'=>'Mailhide Public Key (<a href="http://mailhide.recaptcha.net/apikey">Get One</a>, different from recaptcha):')); $mhpriv=$fsCaptcha->addElement('text','txtMHPrivate', array(),array('label'=>'Mailhide Private Key (<a href="http://mailhide.recaptcha.net/apikey">Get One</a>):')); $rcpub->addRule('required','Field required.'); $rcpriv->addRule('required','Field required.'); $mhpub->addRule('required','Field required.'); $mhpriv->addRule('required','Field required.'); */ $fsSubmit = $form->addElement('fieldset')->setLabel('Create Config'); $fsSubmit->addElement('submit',null,array(),array('label'=>'Finish config and move on to Step 2')); if(!$form->validate()) { include('installheader.php'); include(LIBD.'output.php'); /*?.> <p><b>BEFORE CONTINUING, GO TO <a href="<?=$recaptchaurl?>">RECAPTCHA</a> AND GET API KEY FOR BOTH RECAPTCHA ITSELF AND MAILHIDE! ITS FREE OF CHARGE AND REQUIRED.</b></p> <.?(*/ Output::RenderQF2($form); } else { $_SESSION['allowNewAdminAcct']=true; include('installheader.php'); include(LIBD.'db.php'); include(LIBD.'output.php'); $values=$form->getValue(); define('ADODB_PREFIX',$values['txtSQLPrefix']); define('THISDIR',$values['txtSitePath']);
public function testValidateChecksWhetherFormIsSubmitted() { $form1 = new HTML_QuickForm2('notrack', 'post'); $this->assertFalse($form1->validate()); $form2 = new HTML_QuickForm2('track', 'post'); $this->assertTrue($form2->validate()); }
/** * read_preset_form generates a quickform-object to choose the announcement-preset, * if validated redirect to announcement.php?id=new&cid=$id * * @param object $calendar the actual calendarentry * @return object quickform-object to choose the preset, if validated redirect to new announcement */ private function read_preset_form(&$calendar) { // check sort or from/to $sort = $from = $to = ''; if ($this->get('sort') !== false) { $sort = "&sort=" . $this->get('sort'); } if ($this->get('from') !== false) { $from = "&from=" . $this->get('from'); } if ($this->get('to') !== false) { $to = "&to=" . $this->get('to'); } // form-object $form = new HTML_QuickForm2('choose_preset_' . $calendar->get_id(), 'post', array('name' => 'choose_preset_' . $calendar->get_id(), 'action' => 'calendar.php?id=listall' . $sort . $from . $to)); // add selectfield $select = $form->addSelect('preset', array()); $options = array(0 => parent::lang('class.CalendarView#read_preset_form#select#choosePreset')); $options = $options + Preset::read_all_presets('calendar'); $select->loadOptions($options); $select->addRule('callback', parent::lang('class.CalendarView#read_preset_form#rule#select'), array($this, 'callback_check_select')); // add submit $submit = $form->addSubmit('submit', array('value' => parent::lang('class.CalendarView#read_preset_form#select#submit'))); // validate if ($form->validate()) { // get data $data = $form->getValue(); // insert preset_id in calendar-entry $update = array('preset_id' => $data['preset']); $calendar->update($update); $calendar->write_db('update'); // redirect to listall header('Location: calendar.php?id=listall' . $sort . $from . $to); exit; } else { return $form; } }
public function validate() { $res = $this->isSubmitted() && parent::validate(); if ($res) { $rules = []; $names = []; if ($this->validator_rules) { foreach ($this->validator_rules as $f => $element_rules) { $name = LaraForm::getNameFromDot($f); $elements = $this->getElementsByName($name); if (count($elements)) { $rules[$f] = $element_rules; $names[$f] = '"' . Arr::get($elements, 0)->getLabel() . '"'; } } $validator = \Validator::make($this->getValue(), $rules, $this->validator_messages, $names); if ($validator->fails()) { $errors = []; foreach ($validator->errors()->toArray() as $k => $v) { Arr::set($errors, $k, Arr::get($v, 0)); } //dd($validator->errors()->toArray(), $errors); $this->setErrors($errors); $res = false; } } } return $res; }
/** * 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); } }
/** * 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); } }
public function testContainerValidation() { $form = new HTML_QuickForm2('filters', 'post', null, false); $username = $form->addElement('text', 'foo'); $username->addRule('required', 'Username is required'); $form->addRecursiveFilter('trim'); $this->assertFalse($form->validate()); $this->assertSame('', $username->getValue()); }
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'; echo '<div class="page-header">'; echo ' <h1>Listado de préstamos <small></small></h1>'; echo '</div>'; // Output javascript libraries, needed by hierselect //echo $renderer->getJavascriptBuilder()->getLibraries(true, true); $form->render($renderer); echo $renderer; if (!empty($_REQUEST['btnSubmit']) and $form->validate()) { //$q = strtr($_GET['q'], $normalizeChars); $sql_where = ''; $sql_data = array(); if (!empty($_GET['search'])) { $sql_where .= " and inventario || telefono || apellido_nombre || nro_documento || direccion ilike '%' || ? || '%' "; $sql_data[] = $_GET['search']; } if (!empty($_GET['sindevolucion'])) { $sql_where .= " and fecha_devolucion is null"; } /* * mostramos los resultados */ $sql .= $sql_where . ' order by fecha_prestamo'; //echo $sql;
public function testFormRule() { $form = new HTML_QuickForm2('track', 'post'); $foo = $form->addElement('text', 'foo', array('id' => 'foo')); $form->addRule(new FormRule($form)); $this->assertFalse($form->validate()); $this->assertEquals('an error message', $foo->getError()); }
/** * take creates the form to take an inventoryitem from somebody else * * @param int $did entry-id for the inventoryitem * @return string html-string with the form */ private function take($did) { // check rights if (Rights::check_rights($did, 'inventory')) { // pagecaption $this->tpl->assign('pagecaption', parent::lang('class.InventoryView#page#caption#take')); // get db-object $db = Db::newDb(); // get inventory-object $inventory = new Inventory($did); // check owned if ($inventory->get_owned() == 'given') { // smarty-template $sT = new JudoIntranetSmarty(); // prepare return $return = ''; // get preset $preset = $inventory->get_preset(); // get fields $fields = $preset->get_fields(); // add headline $sT->assign('caption', parent::lang('class.InventoryView#take#page#headline') . ': ' . $inventory->get_name() . ' (' . $inventory->get_inventory_no() . ')'); // add take from $movements = Inventory::movement_last_row($db, $inventory->get_id(), 'user_id', 2); $user = new User(); $user->change_user($movements[1], false, 'id'); $sT->assign('takefrom', parent::lang('class.InventoryView#take#page#TakeFrom') . ': ' . $user->get_userinfo('name')); // add accessory info $sT->assign('accessoryinfo', parent::lang('class.InventoryView#take#page#accessory.required')); // formular $form = new HTML_QuickForm2('inventory_take', 'post', array('name' => 'inventory_take', 'action' => 'inventory.php?id=take&did=' . $this->get('did'))); // renderer $renderer = HTML_QuickForm2_Renderer::factory('default'); $renderer->setOption('required_note', parent::lang('class.InventoryView#entry#form#requiredNote')); // generate field-quickform and add to form foreach ($fields as $field) { // check if given if ($inventory->movement_last_accessories($field) === true || $field->get_type() == 'text') { // generate quickform $field->read_quickform(); } else { // generate quickform $field->read_quickform(array('disabled' => 'disabled')); } // add to form $form->appendChild($field->get_quickform()); } // submit-button $form->addSubmit('submit', array('value' => parent::lang('class.InventoryView#take#form#submitButton'))); // validate if ($form->validate()) { // values $values = $form->getValue(); // write to db $insert_id = $this->movement_to_db('taken', $inventory->get_id(), $_SESSION['user']->userid()); // accessory to db $this->values_to_db($insert_id, $fields, $values); // headline $sT->assign('action', $inventory->get_name() . ' (' . $inventory->get_inventory_no() . ') ' . parent::lang('class.InventoryView#take#page#headline.taken')); // accessory $sT->assign('accessoryaction', parent::lang('class.InventoryView#take#page#accessory.taken')); // walk through fields $data = array(); foreach ($fields as $field) { // check value if (isset($values['inventory-' . $field->get_id()])) { $field_value = $values['inventory-' . $field->get_id()]; } else { $field_value = 0; } // return field and value as HTML $field->value($field_value); $data[] = $field->value_to_html(); } $sT->assign('form', ''); $sT->assign('data', $data); } else { $sT->assign('form', $form->render($renderer)); } // return return $sT->fetch('smarty.inventory.takegive.tpl'); } else { // error $errno = $GLOBALS['Error']->error_raised('NotGivenTo', $this->get('id'), $did); $GLOBALS['Error']->handle_error($errno); return $GLOBALS['Error']->to_html($errno); } } else { // error $errno = $GLOBALS['Error']->error_raised('NotAuthorized', $this->get('id'), $did); $GLOBALS['Error']->handle_error($errno); return $GLOBALS['Error']->to_html($errno); } }
//$form->addElement('static', null) // ->setContent('<div class="col-xs-8 titus">') //; $form->addText("new_lista[{$lista_id}][votos_centro]", $votos_attr_centro); $form->addText("new_lista[{$lista_id}][votos_claustro]", $votos_attr_claustro); //$form->addElement('static', null) // ->setContent('</div>') //; } $form->addElement('button', 'btnSubmit', array('type' => 'submit', 'value' => 'Guardar', 'class' => 'btn btn-lg btn-primary'))->setContent('Guardar'); 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>')); if (isset($_REQUEST['btnSubmit']) and $_REQUEST['btnSubmit'] == 'Guardar' and $form->validate()) { $new_urna = $_REQUEST['new_urna']; $new_lista = $_REQUEST['new_lista']; $db->beginTransaction(); $inserted = 0; foreach ($new_lista as $lista_id => $votos) { unset($new_row); $new_row['urna_id'] = $new_urna; $new_row['lista_id'] = $lista_id; if (isset($votos['votos_centro'])) { $new_row['votos_centro'] = $votos['votos_centro']; } else { $new_row['votos_centro'] = 0; } $new_row['votos_claustro'] = $votos['votos_claustro']; /****************************************************************
/** * new_row inserts a new row in $table * * @param string $table table to insert row * @return string HTML-string for the form or message */ private function new_row($table) { // prepare return $return = ''; // get url-parameters $link = ''; if ($table == 'defaults') { $link = 'administration.php?id=' . $this->get('id'); } else { $link = 'administration.php?id=' . $this->get('id') . '&field=' . $table; } // get db-object $db = Db::newDb(); // prepare statement $sql = "SELECT * FROM {$table}"; // execute $result = $db->query($sql); // table info $tinfo = $result->fetch_fields(); // prepare form $form = new HTML_QuickForm2('new_' . $table, 'post', array('name' => 'new_' . $table, 'action' => $link . '&action=new')); // add datasource (valid = 1) $datasource['valid'] = 1; $form->addDataSource(new HTML_QuickForm2_DataSource_Array($datasource)); // renderer $renderer = HTML_QuickForm2_Renderer::factory('default'); $renderer->setOption('required_note', parent::lang('class.AdministrationView#new_row#form#requiredNote')); // get values and fields $i = 0; $fields = array(); foreach ($tinfo as $col) { // check translation $translated_col = ''; if (parent::lang('class.AdministrationView#tableRows#name#' . $col->name) != "class.AdministrationView#tableRows#name#{$col->name} not translated") { $translated_col = parent::lang('class.AdministrationView#tableRows#name#' . $col->name); } else { $translated_col = $col->name; } // check id if ($col->name != 'id') { // col->type // 252 = text, 253 = varchar; 1 = tinyint(boolean); 3 = int // add field $field = null; // check category if ($col->name == 'category') { // get options $cat_sql = "SELECT id,name FROM category WHERE valid=1"; $cat_result = $db->query($cat_sql); $options = array('--'); while (list($id, $name) = $cat_result->fetch_array(MYSQL_NUM)) { $options[$id] = $name; } // select $field = $form->addElement('select', $col->name, array()); $field->setLabel($translated_col . ':'); // load options $field->loadOptions($options); // add rules if ($table == 'defaults') { $field->addRule('required', parent::lang('class.AdministrationView#new_row#rule#requiredSelect')); $field->addRule('callback', parent::lang('class.AdministrationView#new_row#rule#checkSelect'), array($this, 'callback_check_select')); } } else { // check type if ($col->type == 252) { // textarea $field = $form->addElement('textarea', $col->name, array()); $field->setLabel($translated_col . ':'); // add rules $field->addRule('regex', parent::lang('class.AdministrationView#new_row#rule#regexp.allowedChars') . ' [' . $_SESSION['GC']->get_config('textarea.desc') . ']', $_SESSION['GC']->get_config('textarea.regexp')); // required if ($table == 'defaults') { $field->addRule('required', parent::lang('class.AdministrationView#new_row#rule#required')); } } elseif ($col->type == 253 || $col->type == 3) { // input $field = $form->addElement('text', $col->name, array()); $field->setLabel($translated_col . ':'); // add rules $field->addRule('regex', parent::lang('class.AdministrationView#new_row#rule#regexp.allowedChars') . ' [' . $_SESSION['GC']->get_config('textarea.desc') . ']', $_SESSION['GC']->get_config('textarea.regexp')); // required if ($table == 'defaults') { $field->addRule('required', parent::lang('class.AdministrationView#new_row#rule#required')); } } elseif ($col->type == 1) { // input $field = $form->addElement('checkbox', $col->name, array()); $field->setLabel($translated_col . ':'); } } } // increment field-counter $i++; } // submit-button $form->addSubmit('submit', array('value' => parent::lang('class.AdministrationView#new_row#form#submitButton'))); // validate if ($form->validate()) { // set output $return .= $this->p('class="edit_caption"', parent::lang('class.AdministrationView#new_row#caption#done')); // get data $data = $form->getValue(); // prepare statement $sql = "INSERT INTO {$table} "; $sql_field = "(id,"; $sql_value = " VALUES (NULL,"; foreach ($data as $field => $value) { // check translation $translated_field = ''; if (parent::lang('class.AdministrationView#tableRows#name#' . $field) != "class.AdministrationView#tableRows#name#{$field} not translated") { $translated_field = parent::lang('class.AdministrationView#tableRows#name#' . $field); } else { $translated_field = $field; } // check field if (substr($field, 0, 5) != '_qf__' && $field != 'submit') { // add fields to sql $sql_field .= "{$field},"; $sql_value .= "'{$value}',"; // add fields to output $return .= $this->p('', "{$translated_field} = '" . nl2br(htmlentities(utf8_decode($value))) . "'"); } } $sql_field = substr($sql_field, 0, -1) . ")"; $sql_value = substr($sql_value, 0, -1) . ")"; $sql .= $sql_field . $sql_value; // execute $result = $db->query($sql); // add table content $return .= $this->list_table_content($table, $this->get('page')); } else { $return .= $this->p('', parent::lang('class.AdministrationView#new_row#caption#edit')); $return .= $form->render($renderer); } // return return $return; }
public function testObjectMessageProvider() { $mockProvider = $this->getMock('HTML_QuickForm2_MessageProvider', array('get')); $mockProvider->expects($this->once())->method('get')->will($this->returnValue('A nasty error happened!')); $form = new HTML_QuickForm2('upload', 'post', null, false); $upload = $form->addFile('local', array(), array('messageProvider' => $mockProvider)); $this->assertFalse($form->validate()); $this->assertEquals('A nasty error happened!', $upload->getError()); }
public function testServerSideValidationErrors() { $ds = new HTML_QuickForm2_DataSource_Session(array('foo' => array('', 'blah', ''))); $form = new HTML_QuickForm2('repeatValidate'); $form->addDataSource($ds); $fieldset = new HTML_QuickForm2_Container_Fieldset(); $text = new HTML_QuickForm2_Element_InputText('foo'); $repeat = new HTML_QuickForm2_Container_Repeat(null, null, array('prototype' => $fieldset)); $fieldset->appendChild($text); $form->appendChild($repeat); $text->addRule('required', 'a message'); $this->assertFalse($form->validate()); $ary = $repeat->render(HTML_QuickForm2_Renderer::factory('array'))->toArray(); $this->assertEquals('a message', $ary['elements'][1]['elements'][0]['error']); $this->assertArrayNotHasKey('error', $ary['elements'][2]['elements'][0]); $this->assertEquals('a message', $ary['elements'][3]['elements'][0]['error']); $text->setId('blah-:idx:'); $ary = $repeat->render(HTML_QuickForm2_Renderer::factory('array'))->toArray(); $this->assertEquals('a message', $ary['elements'][1]['elements'][0]['error']); $this->assertArrayNotHasKey('error', $ary['elements'][2]['elements'][0]); $this->assertEquals('a message', $ary['elements'][3]['elements'][0]['error']); }
public function testErrorMessageLocalization() { $form = new HTML_QuickForm2('upload', 'post', null, false); $local = $form->appendChild(new HTML_QuickForm2_Element_InputFile('local', array(), array('language' => 'zz', 'errorMessages' => array('zz' => array(UPLOAD_ERR_CANT_WRITE => 'Blah-blah-blah'))))); $this->assertFalse($form->validate()); $this->assertEquals('Blah-blah-blah', $local->getError()); }
.quickform div.errors ul { margin:0; } .quickform div.error input { border-color: #C00; background-color: #FEF; } .quickform div.qf-checkable label, .quickform div.qf-checkable input { display: inline; float: none; } .quickform div.qf-checkable div, .quickform div.qf-message { margin-left: 170px; } .quickform div.qf-message { font-size: 88%; color: #C00; } </style> <title>HTML_QuickForm2 default renderer example</title> </head> <body> <?php require_once 'HTML/QuickForm2.php'; require_once 'HTML/QuickForm2/Renderer.php'; $form = new HTML_QuickForm2('example'); $fs = $form->addFieldset()->setLabel('Your information'); $username = $fs->addText('username')->setLabel('Username'); $username->addRule('required', 'Username is required'); $password = $fs->addPassword('pass')->setLabel(array('Password', 'Password should be 8 characters at minimum')); $password->addRule('required', 'Password is required'); $form->addHidden('my_hidden1')->setValue('1'); $form->addHidden('my_hidden2')->setValue('2'); $form->addSubmit('submit', array('value' => 'Send', 'id' => 'submit')); if ($form->validate()) { $form->toggleFrozen(true); } $renderer = HTML_QuickForm2_Renderer::factory('default')->setOption(array('group_hiddens' => true, 'group_errors' => true, 'required_note' => '<strong>Note:</strong> Required fields are marked with an asterisk (<em>*</em>).'))->setTemplateForId('submit', '<div class="element">{element} or <a href="/">Cancel</a></div>')->setTemplateForClass('HTML_QuickForm2_Element_Input', '<div class="element<qf:error> error</qf:error>"><qf:error>{error}</qf:error>' . '<label for="{id}" class="qf-label<qf:required> required</qf:required>">{label}</label>' . '{element}' . '<qf:label_2><div class="qf-label-1">{label_2}</div></qf:label_2></div>'); echo $form->render($renderer); ?> </body> </html>
/** * user controles the actions for usersettings * * @return string the html-string of usersettings-page */ private function user() { // smarty-template $sUserPasswd = new JudoIntranetSmarty(); // prepare return $return = ''; // check login if ($_SESSION['user']->get_loggedin()) { // smarty $sUserPasswd->assign('pagecaption', parent::lang('class.MainView#user#caption#general') . ' ' . $_SESSION['user']->get_userinfo('name')); // check action if ($this->get('action') == 'passwd') { // smarty $sUserPasswd->assign('section', parent::lang('class.MainView#user#caption#passwd')); // prepare form $form = new HTML_QuickForm2('passwd', 'post', array('name' => 'passwd', 'action' => 'index.php?id=user&action=passwd')); // add elementgroup $passwd = $form->addElement('group', 'password', array()); // add fields $passwd1 = $passwd->addElement('password', 'password1', array()); $passwd2 = $passwd->addElement('password', 'password2', array()); // add label $passwd->setLabel(parent::lang('class.MainView#user#passwd#label') . ':'); // submit-button $form->addSubmit('submit', array('value' => parent::lang('class.MainView#user#passwd#submitButton'))); // renderer $renderer = HTML_QuickForm2_Renderer::factory('default'); $renderer->setOption('required_note', parent::lang('class.MainView#user#form#requiredNote')); // add rules $passwd->addRule('required', parent::lang('class.MainView#user#rule#required')); $passwd->addRule('callback', parent::lang('class.MainView#user#rule#checkPasswd'), array($this, 'callback_check_passwd')); // validate if ($form->validate()) { // get values $data = $form->getValue(); // get db-object $db = Db::newDb(); // prepare sql-statement $sql = "UPDATE user\n\t\t\t\t\t\t\tSET password='******'password']['password1']) . "'\n\t\t\t\t\t\t\tWHERE id=" . $_SESSION['user']->get_id(); // execute statement $result = $db->query($sql); // smarty message $sUserPasswd->assign('message', parent::lang('class.MainView#user#validate#passwdChanged')); } else { // smarty form and return $sUserPasswd->assign('form', $form->render($renderer)); } return $sUserPasswd->fetch('smarty.user.passwd.tpl'); } else { return 'default content'; } } else { // not authorized $errno = $GLOBALS['Error']->error_raised('NotAuthorized', 'entry:' . $this->get('id'), $this->get('id')); $GLOBALS['Error']->handle_error($errno); return $GLOBALS['Error']->to_html($errno); } }