/**
  * If data source contains explicitly provided null values, those should be used
  * @link http://pear.php.net/bugs/bug.php?id=20295
  */
 public function testBug20295()
 {
     $form = new HTML_QuickForm2('bug20295');
     $hs = $form->addHierselect('hs')->loadOptions(array($this->_primary, $this->_secondary))->setValue(array(1, 12));
     $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('hs' => null)));
     $this->assertNull($hs->getValue());
 }
 public function testSetValueFromSubmitDataSource()
 {
     $form = new HTML_QuickForm2('image', 'post', null, false);
     $foo = $form->appendChild(new HTML_QuickForm2_Element_InputImage('foo'));
     $bar = $form->appendChild(new HTML_QuickForm2_Element_InputImage('bar[idx]'));
     $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('foo_x' => '1234', 'foo_y' => '5678', 'bar' => array('idx' => array('98', '76')))));
     $this->assertEquals(array('x' => '12', 'y' => '34'), $foo->getValue());
     $this->assertEquals(array('x' => '56', 'y' => '78'), $bar->getValue());
     $foo->setAttribute('disabled');
     $this->assertNull($foo->getValue());
 }
 public function testSetValueFromSubmitDataSource()
 {
     $form = new HTML_QuickForm2('submit', 'post', null, false);
     $foo = $form->appendChild(new HTML_QuickForm2_Element_InputSubmit('foo'));
     $bar = $form->appendChild(new HTML_QuickForm2_Element_InputSubmit('bar'));
     $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('foo' => 'Default for foo', 'bar' => 'Default for bar')));
     $this->assertEquals('A button clicked', $foo->getValue());
     $this->assertNull($bar->getValue());
     $foo->setAttribute('disabled');
     $this->assertNull($foo->getValue());
 }
 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());
 }
Example #5
0
 /**
  * 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);
 }
Example #6
0
 /**
  * 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);
 }
 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'));
 }
    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;
}

.separator {
    float: left;
    margin: 0.7em 0 0 0.1em;
}

/* 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 basic elements example</title>
  </head>
  <body>
<?php 
        $renderer = HTML_QuickForm2_Renderer::factory('default');
        $renderer->setElementTemplateForGroupId('nameGrp', 'html_quickform2_element', '<div class="element<qf:error> error</qf:error>"><qf:error><span class="error">{error}</span><br /></qf:error>{element}<br /><label for="{id}"><qf:required><span class="required">* </span></qf:required>{label}</label></div>');
        $renderer->setTemplateForId('nameGrp', '<div class="row"><p class="label"><qf:required><span class="required">*</span></qf:required><qf:label><label>{label}</label></qf:label></p>{content}</div>');
        echo $form->render($renderer);
        ?>
  </body>
</html>
<?php 
    }
Example #9
0
 public function __construct($id, $values, $action)
 {
     parent::__construct($id);
     $this->naziv = new HTML_QuickForm2_Element_InputText('naziv');
     $this->naziv->setAttribute('size', "100%");
     $this->naziv->setLabel('Naziv:');
     $this->naziv->setValue($values["naziv"]);
     $this->naziv->addRule('required', 'Vnesite naziv.');
     $this->naziv->addRule('regex', 'Pri imenu uporabite le črke, številke, narekovaje ali ločila.', '/^[a-zA-Zšč枊ČĆŽ0-9\'\\"-.,;! ]+$/');
     $this->naziv->addRule('maxlength', 'Ime naj bo krajše od 80 znakov.', 80);
     $this->cena = new HTML_QuickForm2_Element_InputText('cena');
     $this->cena->setAttribute('size', "100%");
     $this->cena->setLabel('Cena:');
     $this->cena->setValue($values["cena"]);
     $this->cena->addRule('required', 'Vnesite ceno.');
     $this->cena->addRule('regex', 'Pri ceni uporabite le številke in piko za decimalne zapise.', '/^[0-9.]+$/');
     $this->cena->addRule('maxlength', 'Cena naj bo krajši od 10 znakov.', 10);
     $this->opis = new HTML_QuickForm2_Element_Textarea('opis');
     $this->opis->setAttribute('rows', 5);
     $this->opis->setAttribute('cols', "98%");
     $this->opis->setLabel('Opis:');
     $this->opis->setValue($values["opis"]);
     $this->opis->addRule('required', 'Vnesite opis.');
     $this->opis->addRule('maxlength', 'Opis naj bo krajši od 250 znakov.', 250);
     if ($action != "profil") {
         $this->aktiven = new HTML_QuickForm2_Element_InputCheckbox('aktiven');
         $this->aktiven->setLabel('Aktiven izdelek:');
         if (isset($values["aktiven"]) && $values["aktiven"] == "da") {
             $this->aktiven->setValue(1);
         }
     }
     $this->gumb = new HTML_QuickForm2_Element_InputSubmit(null);
     if ($action == "dodajanje") {
         $this->gumb->setAttribute('value', 'Ustvari izdelek');
     } elseif ($action == "profil") {
         $this->gumb->setAttribute('value', 'Spremeni');
     } else {
         $this->gumb->setAttribute('value', 'Spremeni izdelek');
     }
     $this->addElement($this->naziv);
     $this->addElement($this->cena);
     $this->addElement($this->opis);
     if ($action != "profil") {
         $this->addElement($this->aktiven);
     }
     $this->addElement($this->gumb);
     $this->addRecursiveFilter('trim');
     $this->addRecursiveFilter('htmlspecialchars');
 }
Example #10
0
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;
}
 /**
  * If data source contains explicitly provided null values, those should be used
  * @link http://pear.php.net/bugs/bug.php?id=20295
  */
 public function testBug20295()
 {
     $form = new HTML_QuickForm2('bug20295');
     $el = $form->appendChild(new HTML_QuickForm2_ElementImpl('foo'));
     $el->setValue('not empty');
     $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('foo' => null)));
     $this->assertNull($el->getValue());
 }
Example #12
0
 public static function _renderRequiredNote(HTML_QuickForm2_Renderer $renderer, HTML_QuickForm2 $form)
 {
     if ($renderer->hasRequired && !$form->toggleFrozen(null)) {
         if (($note = $renderer->getOption('required_note')) && !empty($note)) {
             return '<div class="alert alert-info">' . $note . '</div>';
         }
     }
 }
 /**
  * If defaults contain null values, previous values are reused
  * @link http://pear.php.net/bugs/bug.php?id=20295
  */
 public function testBug20295()
 {
     $form = new HTML_QuickForm2('repeat-bug');
     $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('buggy' => array('name' => array(1 => 'First', 2 => 'Second'), 'extra' => array(1 => 'Has extra', 2 => null)))));
     $group = new HTML_QuickForm2_Container_Group('buggy');
     $group->addText('name');
     $group->addText('extra');
     $repeat = $form->addRepeat(null, array('id' => 'buggy-repeat'), array('prototype' => $group));
     $value = $repeat->getValue();
     $this->assertEquals('', $value['buggy']['extra'][2]);
 }
Example #14
0
{
	include('installheader.php');
?>
	<p>Before continuing with the installation, please ensure install/ and includes/ are writable. (<code>chmod -Rv 777 <?=dirname(__FILE__)?> <?=dirname(dirname(__FILE__))?>/includes/</code>)</p>
<?
	include('installfooter.php');
	ob_flush();
	exit(0);
}

if(intval($_GET['page'])==0)
{
	//include('../lib/recaptchalib.php');
	//$recaptchaurl = recaptcha_get_signup_url (null,"FlexCP");
	
	$form = new HTML_QuickForm2('frmInstall');
	$form->addDataSource(new HTML_QuickForm2_DataSource_Array(array(
	    	'txtSiteURL'		=> 'http://'.$_SERVER['HTTP_HOST'].'/',
	    	'txtSitePath'     	=> dirname(dirname(__FILE__)).'/',
		'txtAdminName'		=> 'Sysop',
		'txtSQLHost'		=> 'localhost',
		'txtSQLPrefix'		=> 'atbbs_',
	)));
	$fsMain = $form->addElement('fieldset')->setLabel('Main ATBBS Configuration');

	$sitename	= $fsMain->addElement('text','txtSiteName',	array(),array('label'=>'BBS\'s Name:'));
	$siteurl	= $fsMain->addElement('text','txtSiteURL',	array(),array('label'=>'Site URL:'));
	$sitepath	= $fsMain->addElement('text','txtSitePath',	array(),array('label'=>'Full path to site folder:'));
	$siteemail	= $fsMain->addElement('text','txtSiteEmail',	array(),array('label'=>'Email shown in automails, in the From: header:'));
	$siteadminname  = $fsMain->addElement('text','txtAdminName',	array(),array('label'=>'Used in place of Anonymous when an admin posts:'));
Example #15
0
 public function testSelectMultipleNoOptionsSelectedOnSubmit()
 {
     $options = array('1' => 'Option 1', '2' => 'Option 2');
     $formPost = new HTML_QuickForm2('multiple', 'post', null, false);
     $single1 = $formPost->appendChild(new HTML_QuickForm2_Element_Select('single1', null, array('options' => $options)));
     $single2 = $formPost->appendChild(new HTML_QuickForm2_Element_Select('single2', null, array('options' => $options)));
     $multiple = $formPost->appendChild(new HTML_QuickForm2_Element_Select('mult', array('multiple'), array('options' => $options)));
     $this->assertEquals('1', $single1->getValue());
     $this->assertNull($single2->getValue());
     $this->assertNull($multiple->getValue());
     $formPost->addDataSource(new HTML_QuickForm2_DataSource_Array(array('single1' => '2', 'single2' => '2', 'mult' => array('1', '2'))));
     $this->assertEquals('1', $single1->getValue());
     $this->assertEquals('2', $single2->getValue());
     $this->assertNull($multiple->getValue());
     $formGet = new HTML_QuickForm2('multiple2', 'get', null, false);
     $multiple2 = $formGet->appendChild(new HTML_QuickForm2_Element_Select('mult2', array('multiple'), array('options' => $options)));
     $this->assertNull($multiple2->getValue());
     $formGet->addDataSource(new HTML_QuickForm2_DataSource_Array(array('mult2' => array('1', '2'))));
     $this->assertEquals(array('1', '2'), $multiple2->getValue());
 }
Example #16
0
    if (count($user_karma) == 0) {
        echo 'No karma yet';
    } 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) {
Example #17
0
    $lista_select[$row['k']] = $row['v'];
}
$urna_select = array('' => '-- seleccione --');
$urna_select_sql = 'select urna_id as k, urna_nombre as v from urna order by urna_nombre';
$urna_select_sql_data = array();
$st = $db->prepare($urna_select_sql);
$st->execute($urna_select_sql_data);
while ($row = $st->fetch(PDO::FETCH_ASSOC)) {
    $urna_select[$row['k']] = $row['v'];
}
$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('select', 'new_row[urna_id]', array('autofocus' => 'autofocus'))->setLabel('Urna:')->loadOptions($urna_select)->addRule('required', 'Valor requerido');
$form->addElement('select', 'new_row[lista_id]')->setLabel('Lista:')->loadOptions($lista_select)->addRule('required', 'Valor requerido');
 public function testValidateChecksWhetherFormIsSubmitted()
 {
     $form1 = new HTML_QuickForm2('notrack', 'post');
     $this->assertFalse($form1->validate());
     $form2 = new HTML_QuickForm2('track', 'post');
     $this->assertTrue($form2->validate());
 }
      .quickform div.errors p,
      .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>
Example #20
0
 * If $nextPage is not set, the page is not reached via the page controller.
 * Then check if the viewer is signed in.
 */
if (!isset($nextPage)) {
    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 
Example #21
0
    $result = $dbAccess->SingleQuery($query);
    $arrayAlbum = $result->fetch_row();
    $result->close();
} else {
    // 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>');
/*
 /**
  * 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;
     }
 }
Example #23
0
$db = new PDO($config['db']['dsn']);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$materia_select = array('' => '-- Select --');
$sql_sel = "select materia_id, nombre from materia order by nombre";
$st = $db->query($sql_sel);
while ($row = $st->fetch(PDO::FETCH_ASSOC)) {
    $materia_select[$row['nombre']] = $row['nombre'];
}
*/
$materia_select = $boolean_select;
$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);
}
Example #24
0
<?php

# 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:
Example #25
0
<?php

require_once 'share/data_display.php';
include 'share/form_common.php';
require_once 'HTML/QuickForm2.php';
$sql = <<<END
    select 
        *
    from 
        region
    where
        1 = 1
END;
$sql_data = array();
$form = new HTML_QuickForm2('search', 'get', array('class' => 'noprint'));
// elements
$form->addElement('hidden', 'action')->setValue($action);
$form->addElement('text', 'localidad')->setLabel('Localidad:');
$form->addElement('button', 'btnSubmit', array('type' => 'submit', 'value' => 'Buscar', 'class' => 'btn btn-primary'))->setContent('Buscar');
include 'header.php';
echo '<div class="page-header">';
echo '<h1>Lista de regiones <small>Ordenado por pais, provincia, localidad</small></h1>';
echo '<div class="noprint">';
echo '<a href="?action=region_insert">Cargar Región</a>';
echo '</div>';
echo '</div>';
echo $form;
// procesamos la busqueda
$sql_where = '';
if (isset($_GET['btnSubmit']) and $_GET['btnSubmit'] != '') {
    $sql_data = array();
 /**
  * If data source contains explicitly provided null values, those should be used
  * @link http://pear.php.net/bugs/bug.php?id=20295
  */
 public function testBug20295()
 {
     $form = new HTML_QuickForm2('bug20295');
     $ms = $form->addSelect('multiselect', array('multiple'))->loadOptions(array('one' => 'First option', 'two' => 'Second option'))->setValue(array('two'));
     // data source searching should stop on finding this null
     $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('multiselect' => null)));
     $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('multiselect' => array('one'))));
     $this->assertNull($ms->getValue());
 }
 /**
  * If data source contains explicitly provided null values, those should be used
  * @link http://pear.php.net/bugs/bug.php?id=20295
  */
 public function testBug20295()
 {
     $form = new HTML_QuickForm2('bug20295');
     $date = $form->addDate('aDate', null, array('format' => 'Ymd'))->setValue('today');
     $form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('aDate' => null)));
     $this->assertNull($date->getValue());
 }
    echo '<fieldset' . $fieldset->getAttributes(true) . ">\n<legend>" . $fieldset->getLabel() . "</legend>\n";
    foreach ($fieldset as $element) {
        output_element($element);
    }
    echo "</fieldset>\n";
}
// in real application the password check will a bit be different, of course
function check_password($password)
{
    return $password == 'qwerty';
}
//
// Form setup
//
require_once 'HTML/QuickForm2.php';
$form = new HTML_QuickForm2('basicRules');
// for file upload to work
$form->setAttribute('enctype', 'multipart/form-data');
// data source with default values:
$form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('testUsername' => 'luser')));
// override whatever value was submitted
$form->addElement('hidden', 'MAX_FILE_SIZE')->setValue('102400');
//
// Simple fields validation, rule chaining
//
$fsAuth = $form->addElement('fieldset')->setLabel('Auth credentials');
$username = $fsAuth->addElement('text', 'testUsername', array('style' => 'width: 200px;'))->setLabel('Username (letters only):');
$fsPasswords = $fsAuth->addElement('fieldset')->setLabel('Supply password only if you want to change it');
$oldPassword = $fsPasswords->addElement('password', 'oldPassword', array('style' => 'width: 200px;'))->setLabel('Old password (<i>qwerty</i>):');
$newPassword = $fsPasswords->addElement('password', 'newPassword', array('style' => 'width: 200px;'))->setLabel('New password (min 6 chars):');
$repPassword = $fsPasswords->addElement('password', 'newPasswordRepeat', array('style' => 'width: 200px;'))->setLabel('Repeat new password:');
Example #29
0
    order by
        cantidad desc
END;
$zona_select = array('' => '--Todas--', 'Norte' => 'Norte', 'Centro' => 'Centro', 'Buenos Aires' => 'Buenos Aires', 'Sur' => 'Sur', 'Nacional y Agencias' => 'Nacional y Agencias');
$mencion_escala[''] = '--Todas--';
$mencion_escala['NSP'] = 'Nota sobre el programa (NSP)';
$mencion_escala['MP'] = 'Mención del programa (MP)';
$mencion_escala['TR'] = 'Tema relacionado (TR)';
$pcia_select = array(null => '--Todas--', 'N/A' => 'Nacional y Agencias', 'Chaco' => 'Chaco', 'Jujuy' => 'Jujuy', 'Corriente' => 'Corrientes', 'Misiones' => 'Misiones', 'Salta' => 'Salta', 'Catamarca' => 'Catamarca', 'Formosa' => 'Formosa', 'Santiago del Estero' => 'Santiago del Estero', 'Tucuman' => 'Tucuman', 'Santa Fe' => 'Santa Fe', 'Cordoba' => 'Cordoba', 'Entre Rios' => 'Entre Rios', 'San Juan' => 'San Juan', 'Mendoza' => 'Mendoza', 'San Luis' => 'San Luis', 'La Pampa' => 'La Pampa', 'La Rioja' => 'La Rioja', 'Buenos Aires' => 'Buenos Aires', 'Rio Negro' => 'Rio Negro', 'Neuquen' => 'Neuquen', 'Chubut' => 'Chubut', 'Santa Cruz' => 'Santa Cruz', 'Tierra del Fuego' => 'Tierra del Fuego');
$valoracion_select[''] = '--Seleccione--';
$valoracion_select['+1'] = 'Positiva (+1)';
$valoracion_select['0'] = 'Neutra (0)';
$valoracion_select['-1'] = 'Negativa (-1)';
$valoracion_select['-2'] = 'Denuncia (-2)';
//$form_params = params_encode($params);
$form = new HTML_QuickForm2('search', 'get');
// elements
$form->addElement('hidden', 'action')->setValue($action);
$form->addElement('select', 'zona', $campo_corto)->setLabel('Zona:')->loadOptions($zona_select);
$form->addElement('select', 'provincia', $campo_medio)->setLabel('Provincia:')->loadOptions($pcia_select);
$form->addElement('text', 'medio', $campo_medio)->setLabel('Medio:');
$form->addElement('select', 'mencion')->setLabel('Mención:')->loadOptions($mencion_escala);
$form->addElement('select', 'valoracion')->setLabel('Valoración:')->loadOptions($valoracion_select);
$form->addElement('text', 'texto', $campo_largo)->setLabel('Texto:');
$form->addElement('date', 'fecha_carga_desde', $campo_corto, array('addEmptyOption' => true, 'emptyOptionText' => array('Y' => 'Anio:', 'M' => 'Mes:', 'd' => 'Dia:')))->setLabel('Fecha carga desde:');
$form->addElement('date', 'fecha_carga_hasta', $campo_corto, array('addEmptyOption' => true, 'emptyOptionText' => array('Y' => 'Anio:', 'M' => 'Mes:', 'd' => 'Dia:')))->setLabel('Fecha carga hasta:');
$submit = $form->addSubmit('btnSubmit', array('value' => 'Buscar'))->addClass(array('btn', 'btn-primary'));
////////////////////////////////////////////////////////////
// renderer fixes
function renderSubmit($renderer, $submit)
{
Example #30
0
                break;
        }
    }
}
$row = package::info((int) $_GET['id']);
if (empty($row['name'])) {
    report_error('Illegal package id');
    response_footer();
    exit;
}
print_package_navigation($row['packageid'], $row['name'], '/package-edit.php?id=' . $row['packageid']);
$sth = $dbh->query('SELECT id, name FROM categories ORDER BY name');
while ($cat_row = $sth->fetchRow(DB_FETCHMODE_ASSOC)) {
    $rows[$cat_row['id']] = $cat_row['name'];
}
$form = new HTML_QuickForm2('package-edit', 'post', array('action' => '/package-edit.php?id=' . $row['packageid']));
$form->removeAttribute('name');
$renderer = HTML_QuickForm2_Renderer::factory('default');
// Set defaults for the form elements
$form->addDataSource(new HTML_QuickForm2_DataSource_Array(array('name' => htmlspecialchars($row['name']), 'license' => htmlspecialchars($row['license']), 'summary' => htmlspecialchars($row['summary']), 'description' => htmlspecialchars($row['description']), 'category' => (int) $row['categoryid'], 'homepage' => htmlspecialchars($row['homepage']), 'doc_link' => htmlspecialchars($row['doc_link']), 'bug_link' => htmlspecialchars($row['bug_link']), 'cvs_link' => htmlspecialchars($row['cvs_link']), 'unmaintained' => $row['unmaintained'] ? true : false, 'newpk_id' => (int) $row['newpk_id'], 'new_channel' => htmlspecialchars($row['new_channel']), 'new_package' => htmlspecialchars($row['new_package']))));
$form->addElement('text', 'name', array('maxlength' => "80", 'accesskey' => "c"))->setLabel('Pa<span class="accesskey">c</span>kage Name');
$form->addElement('text', 'license', array('maxlength' => "50", 'placeholder' => 'BSD'))->setLabel('License:');
$form->addElement('textarea', 'summary', array('cols' => "75", 'rows' => "7", 'maxlength' => "255"))->setLabel('Summary');
$form->addElement('textarea', 'description', array('cols' => "75", 'rows' => "12"))->setLabel('Description');
$form->addElement('select', 'category')->setLabel('Category:')->loadOptions($rows);
$manager = new Tags_Manager();
$sl = $form->addElement('select', 'tags', array('multiple' => 'multiple'))->setLabel('Tags:')->loadOptions(array('' => '(none)') + $manager->getTags(false, true));
$sl->setValue(array_keys($manager->getTags($row['name'], true)));
$form->addElement('text', 'homepage', array('maxlength' => 255, 'accesskey' => "O"))->setLabel('H<span class="accesskey">o</span>mepage:');
$form->addElement('text', 'doc_link', array('maxlength' => 255, 'placeholder' => 'http://example.com/manual'))->setLabel('Documentation URI:');
$form->addElement('url', 'bug_link', array('maxlength' => 255, 'placeholder' => 'http://example.com/bugs'))->setLabel('Bug Tracker URI:');