public function testGroupErrors() { $form = new HTML_QuickForm2('testGroupErrors'); $text = $form->addText('anElement', array('id' => 'anElement'))->setError('an error'); $renderer = HTML_QuickForm2_Renderer::factory('stub'); $renderer->setOption('group_errors', false); $form->render($renderer); $this->assertEquals(array(), $renderer->getErrors()); $renderer->setOption('group_errors', true); $form->render($renderer); $this->assertEquals(array('anElement' => 'an error'), $renderer->getErrors()); }
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]); }
public function testRenderGroupedErrors() { $form = new HTML_QuickForm2('groupedErrors'); $element = $form->addText('testGroupedErrors')->setError('Some error'); $renderer = HTML_Quickform2_Renderer::factory('callback')->setOption(array('group_errors' => true, 'errors_prefix' => 'Your errors:', 'errors_suffix' => '')); $this->assertContains('<div class="errors"><p>Your errors:</p><ul><li>Some error</li></ul></div>', $form->render($renderer)->__toString()); }
} require_once 'lib/pear/HTML/QuickForm2.php'; $form = new HTML_QuickForm2('form', 'post', array('role' => 'form')); // fields // elements $form->addElement('hidden', 'action')->setValue($this_action); $form->addElement('select', 'new_urna', array('autofocus' => 'autofocus'))->setLabel('Urna:')->loadOptions($urna_select)->addRule('required', 'Valor requerido'); $votos_attr_centro = array('class' => 'form-inline col-xs-3', 'maxlength' => 3, 'pattern' => '\\d*', 'title' => 'Debe introducir solo numeros', 'placeholder' => 'Votos Centro'); $votos_attr_claustro = array('class' => 'form-inline col-xs-3', 'maxlength' => 3, 'pattern' => '\\d*', 'title' => 'Debe introducir solo numeros', 'placeholder' => 'Votos Claustro'); foreach ($lista_select as $lista_id => $lista_nombre) { unset($votos); $form->addElement('static', null)->setContent('<label for="votos" class="col-xs-6 text-right control-label">' . $lista_nombre . ':</label>'); //$form->addElement('static', null) // ->setContent('<div class="col-xs-8 titus">') //; $form->addText("new_lista[{$lista_id}][votos_centro]", $votos_attr_centro); $form->addText("new_lista[{$lista_id}][votos_claustro]", $votos_attr_claustro); //$form->addElement('static', null) // ->setContent('</div>') //; } $form->addElement('button', 'btnSubmit', array('type' => 'submit', 'value' => 'Guardar', 'class' => 'btn btn-lg btn-primary'))->setContent('Guardar'); require_once 'HTML/QuickForm2/Renderer.php'; require_once 'HTML/QuickForm2/JavascriptBuilder.php'; $renderer = HTML_QuickForm2_Renderer::factory('default'); //$renderer->setJavascriptBuilder(new HTML_QuickForm2_JavascriptBuilder(null, __DIR__ . '/../lib/pear/data/HTML_QuickForm2/js')); $renderer->setOption(array('errors_prefix' => 'El formulario contiene errores:', 'required_note' => '<div><span class="required">*</span> denota campos requeridos</div>')); if (isset($_REQUEST['btnSubmit']) and $_REQUEST['btnSubmit'] == 'Guardar' and $form->validate()) { $new_urna = $_REQUEST['new_urna']; $new_lista = $_REQUEST['new_lista']; $db->beginTransaction();
public function testInput() { $form = new HTML_QuickForm2('filters', 'post', null, false); $foo = $form->addText('foo'); $this->assertEquals($_POST['foo'], $foo->getValue()); $foo->addFilter('trim'); $this->assertEquals(trim($_POST['foo']), $foo->getValue()); }