本文整理汇总了PHP中HTML_QuickForm2::render方法的典型用法代码示例。如果您正苦于以下问题:PHP HTML_QuickForm2::render方法的具体用法?PHP HTML_QuickForm2::render怎么用?PHP HTML_QuickForm2::render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTML_QuickForm2
的用法示例。
在下文中一共展示了HTML_QuickForm2::render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGroupHiddens
public function testGroupHiddens()
{
$form = new HTML_QuickForm2('testGroupHiddens', 'post', null, false);
$hidden = $form->addHidden('aHiddenElement');
$renderer = HTML_QuickForm2_Renderer::factory('stub');
$renderer->setOption('group_hiddens', false);
$form->render($renderer);
$this->assertEquals(array(), $renderer->getHidden());
$renderer->setOption('group_hiddens', true);
$form->render($renderer);
$this->assertEquals(array($hidden->__toString()), $renderer->getHidden());
}
示例2: isset
{
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_once 'header.php';
echo '<div class="page-header">';
echo ' <img class="pull-right" src="img/logo_sumar_small.png">';
echo ' <h1>Búsqueda de notas</h1>';
echo '</div>';
// Output javascript libraries, needed by hierselect
//echo $renderer->getJavascriptBuilder()->getLibraries(true, true);
$form->render($renderer);
echo '<div class="noprint">';
echo $renderer;
echo '</div>';
if (isset($_GET['btnSubmit']) and $_GET['btnSubmit'] != '') {
$q = isset($_GET['texto']) ? strtr($_GET['texto'], $normalizeChars) : '';
$sql_where = '';
$sql_data = array();
//$new_row = $_GET['new_row'];
// $fecha_desde = get_date($new_row['fecha1_desde']) . ' 00:00:00';
// $fecha_hasta = get_date($new_row['fecha1_hasta']) . ' 23:59:59';
// $sql_data = array($fecha_desde, $fecha_hasta);
if (!empty($_GET['zona'])) {
$sql_where .= " and lower(m.zona) like '%' || lower(?) || '%' ";
$sql_data[] = $_GET['zona'];
}
示例3: array
$form->addElement('checkbox', 'unmaintained')->setLabel('Is this package unmaintained ?');
$packages = package::listAllwithReleases();
$rows = array(0 => '');
foreach ($packages as $id => $info) {
if ($id == $_GET['id']) {
continue;
}
$rows[$id] = $info['name'];
}
$form->addElement('select', 'newpk_id')->setLabel('Superseeded by:')->loadOptions($rows);
$form->addElement('text', 'new_channel', array('maxlength' => 255, 'placeholder' => 'pear.phpunit.de'))->setLabel('Moved to channel:');
$form->addElement('text', 'new_package', array('maxlength' => 255, 'placeholder' => 'PHPUnit'));
$form->addElement('submit', 'submit')->setLabel('Save Changes');
$csrf_token_value = create_csrf_token($csrf_token_name);
$form->addElement('hidden', $csrf_token_name)->setValue($csrf_token_value);
print $form->render($renderer);
?>
<table class="form-holder" cellspacing="1">
<caption class="form-caption">Manage Releases</caption>
<tr>
<th class="form-label_top">Version</th>
<th class="form-label_top">Release Date</th>
<th class="form-label_top">Actions</th>
</tr>
<?php
foreach ($row['releases'] as $version => $release) {
echo "<tr>\n";
echo ' <td class="form-input">' . htmlspecialchars($version) . "</td>\n";
示例4: edit
/**
* edit edits the given entry
*
* @param int $cid entry-id for calendar
* @return string html-string
*/
private function edit($cid)
{
// check rights
if (Rights::check_rights($cid, 'calendar')) {
// smarty-templates
$sD = new JudoIntranetSmarty();
// get calendar-object
$calendar = new Calendar($cid);
// pagecaption
$this->tpl->assign('pagecaption', parent::lang('class.CalendarView#page#caption#edit') . ": \"{$cid}\" (" . $calendar->get_name() . ")");
// get rights
$cRights = $calendar->get_rights()->get_rights();
// check public access
$kPublicAccess = array_search(0, $cRights);
$publicAccess = false;
if ($kPublicAccess !== false) {
$publicAccess = true;
unset($cRights[$kPublicAccess]);
}
// prepare return
$return = '';
$form = new HTML_QuickForm2('edit_calendar_entry', 'post', array('name' => 'edit_calendar_entry', 'action' => 'calendar.php?id=edit&cid=' . $cid));
$now_year = (int) date('Y');
$year_min = $now_year;
$year_max = $now_year + 3;
// get datasource
$datasource = array('date' => $calendar->get_date(), 'name' => $calendar->get_name(), 'shortname' => $calendar->get_shortname(), 'type' => $calendar->return_type(), 'entry_content' => $calendar->get_content(), 'rights' => $cRights);
// add public access
if ($publicAccess) {
$datasource['public'] = 1;
}
$form->addDataSource(new HTML_QuickForm2_DataSource_Array($datasource));
// renderer
$renderer = HTML_QuickForm2_Renderer::factory('default');
$renderer->setOption('required_note', parent::lang('class.CalendarView#entry#form#requiredNote'));
// elements
// date
$date = $form->addElement('text', 'date', array());
$date->setLabel(parent::lang('class.CalendarView#entry#form#date') . ':');
// rule
$date->addRule('required', parent::lang('class.CalendarView#entry#rule#required.date'));
$date->addRule('callback', parent::lang('class.CalendarView#entry#rule#check.date'), array($this, 'callback_check_date'));
// add jquery-datepicker
// smarty
$sD->assign('elementid', 'date-0');
$sD->assign('dateFormat', 'yy-mm-dd');
$sD->assign('dateValue', $calendar->get_date());
$this->add_jquery($sD->fetch('smarty.js-datepicker.tpl'));
// name
$name = $form->addElement('text', 'name');
$name->setLabel(parent::lang('class.CalendarView#entry#form#name') . ':');
$name->addRule('required', parent::lang('class.CalendarView#entry#rule#required.name'));
$name->addRule('regex', parent::lang('class.CalendarView#entry#rule#regexp.allowedChars') . ' [' . $_SESSION['GC']->get_config('name.desc') . ']', $_SESSION['GC']->get_config('name.regexp'));
// shortname
$shortname = $form->addElement('text', 'shortname');
$shortname->setLabel(parent::lang('class.CalendarView#entry#form#shortname') . ':');
$shortname->addRule('regex', parent::lang('class.CalendarView#entry#rule#regexp.allowedChars') . ' [' . $_SESSION['GC']->get_config('name.desc') . ']', $_SESSION['GC']->get_config('name.regexp'));
// type
$options = array_merge(array(0 => '--'), Calendar::return_types());
$type = $form->addElement('select', 'type');
$type->setLabel(parent::lang('class.CalendarView#entry#form#type') . ':');
$type->loadOptions($options);
$type->addRule('required', parent::lang('class.CalendarView#entry#rule#required.type'));
$type->addRule('callback', parent::lang('class.CalendarView#entry#rule#check.select'), array($this, 'callback_check_select'));
// entry_content
$content = $form->addElement('textarea', 'entry_content');
$content->setLabel(parent::lang('class.CalendarView#entry#form#entry_content') . ':');
$content->addRule('regex', parent::lang('class.CalendarView#entry#rule#regexp.allowedChars') . ' [' . $_SESSION['GC']->get_config('textarea.desc') . ']', $_SESSION['GC']->get_config('textarea.regexp'));
// select rights
$options = $_SESSION['user']->return_all_groups('sort');
$rights = $form->addElement('select', 'rights', array('multiple' => 'multiple', 'size' => 5));
$rights->setLabel(parent::lang('class.CalendarView#entry#form#rights') . ':');
$rights->loadOptions($options);
// checkbox public
$rights = $form->addElement('checkbox', 'public');
$rights->setLabel(parent::lang('class.CalendarView#entry#form#public') . ':');
// submit-button
$form->addElement('submit', 'submit', array('value' => parent::lang('class.CalendarView#entry#form#submitButton')));
// validate
if ($form->validate()) {
// create calendar-object
$data = $form->getValue();
// check $data['rights']
if (!isset($data['rights'])) {
$data['rights'] = array();
}
// merge with own groups, add admin
$data['rights'] = array_merge($data['rights'], $_SESSION['user']->get_groups(), array(1));
// add public access
$kPublicAccess = array_search(0, $data['rights']);
if ($kPublicAccess === false && isset($data['public']) && $data['public'] == 1) {
$data['rights'][] = 0;
} elseif ($kPublicAccess !== false && !isset($data['public'])) {
unset($data['rights'][$kPublicAccess]);
//.........这里部分代码省略.........
示例5: render
public function render(\HTML_QuickForm2_Renderer $renderer)
{
$this->_initValues();
return parent::render($renderer);
}
示例6: edit
/**
* 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);
//.........这里部分代码省略.........
示例7: correct
/**
* 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) {
//.........这里部分代码省略.........
示例8: testRenderWithStyle
public function testRenderWithStyle()
{
$form = new HTML_QuickForm2('arrayStyle');
$text1 = $form->addText('foo', array('id' => 'testArrayWithStyle'));
$text2 = $form->addText('bar', array('id' => 'testArrayWithoutStyle'));
$renderer = HTML_Quickform2_Renderer::factory('array')->setStyleForId('testArrayWithStyle', 'weird');
$array = $form->render($renderer)->toArray();
$this->assertEquals('weird', $array['elements'][0]['style']);
$this->assertArrayNotHasKey('style', $array['elements'][1]);
}
示例9: testRenderGroupedHiddens
public function testRenderGroupedHiddens()
{
$form = new HTML_QuickForm2('groupedHiddens');
$hidden1 = $form->addHidden('hidden1');
$hidden2 = $form->addHidden('hidden2');
$renderer = HTML_Quickform2_Renderer::factory('callback')->setOption('group_hiddens', false);
$html = $form->render($renderer)->__toString();
$this->assertContains('<div style="display: none;">' . $hidden1->__toString() . '</div>', $html);
$this->assertContains('<div style="display: none;">' . $hidden2->__toString() . '</div>', $html);
$renderer->setOption('group_hiddens', true);
$html = $form->render($renderer)->__toString();
// why not ?
// $this->assertNotContains('<div style="display: none;">', $html);
$this->assertContains($hidden1->__toString() . $hidden2->__toString(), $html);
}
示例10: render
public function render(HTML_QuickForm2_Renderer $renderer)
{
if (method_exists($renderer->getJavascriptBuilder(), 'addValidateJs')) {
$renderer->getJavascriptBuilder()->addValidateJs('errorElement: "span"');
}
Am_Di::getInstance()->hook->call(Am_Event::FORM_BEFORE_RENDER, array('form' => $this));
return parent::render($renderer);
}
示例11: render
public function render(HTML_QuickForm2_Renderer $renderer)
{
if (method_exists($renderer->getJavascriptBuilder(), 'addValidateJs')) {
$renderer->getJavascriptBuilder()->addValidateJs('errorElement: "span"');
}
return parent::render($renderer);
}
示例12: take
/**
* 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);
}
}
示例13: new_row
/**
* 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++;
//.........这里部分代码省略.........
示例14: renderForm
protected function renderForm(HTML_QuickForm2 $form)
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
/* Set up custom font and form width */
body {
margin-left: 10px;
font-family: Arial,sans-serif;
font-size: small;
}
.quickform {
min-width: 500px;
max-width: 600px;
width: 560px;
}
.quickform input.bigred {font-weight: bold; background: #FF6666;}
.quickform input.flat {border-style: solid; border-width: 2px; border-color: #000000;}
/* Use default styles included with the package */
<?php
if ('@data_dir@' != '@' . 'data_dir@') {
$filename = '@data_dir@/HTML_QuickForm2/quickform.css';
} else {
$filename = dirname(dirname(dirname(__FILE__))) . '/data/quickform.css';
}
readfile($filename);
?>
</style>
<title>HTML_QuickForm2 simple controller example</title>
</head>
<body>
<?php
$renderer = HTML_QuickForm2_Renderer::factory('default');
$renderer->setTemplateForId('tabs', '<div style="float: right;">{content}</div>');
echo $form->render($renderer);
?>
</body>
</html>
<?php
}
示例15: user
/**
* 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='" . md5($data['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);
}
}