Exemplo n.º 1
0
 public function testBase()
 {
     $field = Builder::choose(['value1' => Builder::radio()->label('Value 1'), 'value2' => Builder::radio()->label('Value 2'), 'value3' => Builder::radio()->label('Value 3'), 'value4' => Builder::radio()->label('Value 4')]);
     $this->assertInstanceOf('FormManager\\Containers\\Choose', $field);
     $this->assertInstanceOf('FormManager\\Fields\\Radio', $field['value1']);
     return $field;
 }
Exemplo n.º 2
0
 public function testBasic()
 {
     $this->_testElement(Builder::radio());
     $this->_testField(Builder::radio());
     $this->_testRequired(Builder::radio());
     $this->_testCheckUncheck(Builder::radio());
 }
Exemplo n.º 3
0
 /**
  * @depends testBase
  */
 public function testFields(Form $form)
 {
     $form->add(['name' => Builder::text()->maxlength(50)->required()->label('Your name'), 'email' => Builder::email()->required()->label('Your email'), 'telephone' => Builder::tel()->required()->label('Telephone number'), 'avatar' => Builder::file()->required()->label('Avatar'), 'gender' => Builder::choose(['m' => Builder::radio()->label('Male'), 'f' => Builder::radio()->required()->label('Female')]), 'born' => Builder::group(['day' => Builder::number()->required()->min(1)->max(31)->label('Day'), 'month' => Builder::number()->required()->min(1)->max(12)->label('Month'), 'year' => Builder::number()->required()->min(1900)->max(2013)->label('Year')]), 'language' => Builder::select()->required()->options(array('gl' => 'Galician', 'es' => 'Spanish', 'en' => 'English'))->label('Language'), 'friends' => Builder::collection(['name' => Builder::text()->required()->label('Name'), 'email' => Builder::email()->required()->label('email'), 'age' => Builder::number()->required()->label('Age')]), 'action' => Builder::choose(['save' => Builder::submit()->html('Save changes'), 'duplicate' => Builder::submit()->html('Save as new value')])]);
     $this->assertCount(9, $form);
     $this->assertInstanceOf('FormManager\\Fields\\Text', $form['name']);
     $this->assertInstanceOf('FormManager\\Fields\\Submit', $form['action']['save']);
     $this->assertSame($form, $form['action']['save']->getForm());
     return $form;
 }
Exemplo n.º 4
0
<?php

require __DIR__ . '/src/autoloader.php';
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', __DIR__ . '/php.log');
use FormManager\Builder as F;
use FormManager\InvalidValueException;
$form = F::Form(['data' => F::group(['dia' => F::number()->label('Dia'), 'mes' => F::number()->label('Mes')]), 'colores' => F::choose(['red' => F::radio()->label('Red'), 'blue' => F::radio()->label('Blue'), 'green' => F::radio()->label('Green')]), 'personas' => F::collection(['nome' => F::text()->label('Nome'), 'apelido' => F::text()->label('Apelidos')]), 'bloques' => F::collectionMultiple(['texto' => ['titulo' => F::text()->label('Titulo'), 'texto' => F::textarea()->label('Texto')], 'cita' => ['texto' => F::textarea()->label('Texto'), 'autor' => F::text()->label('Autor')]]), 'enviar' => F::submit()->html('Enviar')]);
$form->fieldsets(['personal' => ['nome' => F::text()->label('O teu nome')->addValidator(function ($input) {
    if ($input->val() !== 'Lolo') {
        throw new InvalidValueException('Nome non valido, debe ser Lolo');
    }
})->datalist(['Lolo' => 'Lolo', 'Manolo' => 'Manolo']), 'apelido' => F::text()->label('O teu apelido'), 'idade' => F::select()->options([1 => 'Menor de idade', 2 => 'Maiore de idade'])->label('Idade')->render(function ($input) {
    return '<p>' . $input . '</p>';
})]]);
$form['nome']->errorLabel->class('my-error');
$form->loadFromGlobals();
if (!$form->isValid()) {
    echo 'Invalid values';
}
echo $form;