当前位置: 首页>>代码示例>>PHP>>正文


PHP HTML_QuickForm2::addElement方法代码示例

本文整理汇总了PHP中HTML_QuickForm2::addElement方法的典型用法代码示例。如果您正苦于以下问题:PHP HTML_QuickForm2::addElement方法的具体用法?PHP HTML_QuickForm2::addElement怎么用?PHP HTML_QuickForm2::addElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HTML_QuickForm2的用法示例。


在下文中一共展示了HTML_QuickForm2::addElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testRequest16806

 /**
  * 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'));
 }
开发者ID:andreaswarnaar,项目名称:HTML_QuickForm2.1,代码行数:14,代码来源:InputCheckboxTest.php

示例2: addElement

 /**
  * 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);
 }
开发者ID:nnnnathann,项目名称:piwik,代码行数:19,代码来源:QuickForm2.php

示例3: addElement

 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;
 }
开发者ID:alexanderTsig,项目名称:arabic,代码行数:8,代码来源:Form.php

示例4: populateFormOnce

 /**
  * 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;
     }
 }
开发者ID:N3X15,项目名称:ATBBS-Plus,代码行数:13,代码来源:Page.php

示例5: testPerform

 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'));
 }
开发者ID:andreaswarnaar,项目名称:HTML_QuickForm2.1,代码行数:20,代码来源:BackTest.php

示例6: printForm

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;
}
开发者ID:stof,项目名称:pearweb,代码行数:24,代码来源:account-mail.php

示例7: array

    // 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('&nbsp;');
$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&amp;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');
开发者ID:GunnarWinqvist,项目名称:SSKL,代码行数:31,代码来源:PEditAlbum.php

示例8: array

$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';
开发者ID:sergiokessler,项目名称:perio,代码行数:31,代码来源:material_form.php

示例9: delete

 /**
  * 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);
     }
 }
开发者ID:BackupTheBerlios,项目名称:judointranet,代码行数:51,代码来源:class.CalendarView.php

示例10: die

    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:'));
开发者ID:GunnarWinqvist,项目名称:SSKL,代码行数:31,代码来源:PApplication.php

示例11: get_form_html

 /**
  * 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;
 }
开发者ID:WillSwales,项目名称:financial-maths-mediawiki,代码行数:48,代码来源:class-ct1-render.php

示例12: htmlspecialchars

    } 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&amp;handle=%s&amp;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:&nbsp;');
    $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>&nbsp;</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));
开发者ID:stof,项目名称:pearweb,代码行数:31,代码来源:karma.php

示例13: header

# 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()) {
开发者ID:raynaldmo,项目名称:php-education,代码行数:30,代码来源:add_page.php

示例14: array

$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>'));
开发者ID:sergiokessler,项目名称:perio,代码行数:31,代码来源:urna_form.php

示例15: array

?>
    </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:'));
$area = $fsText->addElement('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:'));
$fsNested->addElement('password', 'passTest', array('style' => 'width: 200px'), array('label' => 'Password:'));
// Now we move the fieldset into another fieldset!
$fsText->insertBefore($fsNested, $area);
// selects
$fsSelect = $form->addElement('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:'));
开发者ID:andreaswarnaar,项目名称:HTML_QuickForm2.1,代码行数:31,代码来源:basic-elements.php


注:本文中的HTML_QuickForm2::addElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。