Пример #1
0
 public function testSelectField()
 {
     $this->generate(function ($f) {
         $f->select('foo', 'Test field', FormOptions::fromArray(['a', 'b', 'c']), ['selected' => 1]);
     });
     $this->validate([['form_start'], ['label_start', ['for' => 'id_foo']], ['content', 'Test field'], ['label_end'], ['select_start', ['name' => 'foo', 'id' => 'id_foo']], ['option_start', ['value' => 0]], ['content', 'a'], ['option_end'], ['option_start', ['value' => 1, 'selected' => '']], ['content', 'b'], ['option_end'], ['option_start', ['value' => 2]], ['content', 'c'], ['option_end'], ['select_end'], ['form_end']]);
 }
Пример #2
0
<?php

/*~*/
use NitroXy\PHPForms\Form;
use NitroXy\PHPForms\FormOptions;
class MyCustomClass extends stdClass
{
}
$myObject = new MyCustomClass();
$myObject->name = 'John Doe';
$myObject->age = 46;
$myObject->role = 2;
/* frobnicator */
$myObject->description = 'Lorem ipsum dot sit amet.';
Form::fromObject($myObject, function ($f) {
    $f->textField('name', 'Name');
    $f->textField('age', 'Age', ['type' => 'number', 'min' => 1]);
    $f->select('role', 'Role', FormOptions::fromArray(['', 'Manager', 'Frobnicator', 'Developer']));
    $f->textarea('description', 'Description');
}, ['layout' => 'bootstrap']);
Пример #3
0
<?php

/*~*/
use NitroXy\PHPForms\Form;
use NitroXy\PHPForms\FormOptions;
global $layout;
Form::create('smoketest', function ($f) {
    $f->hiddenField('name', 'Hidden (this wont show at all)', ['value' => '8']);
    $f->textField('text_field', 'Text', ['hint' => 'Use the "type" option to use custom type such as number.']);
    $f->passwordField('password_field', 'Password', ['hint' => 'Passwords are not persistent if autocomplete is off', 'autocomplete' => 'off']);
    $f->customField('custom_field', 'email', 'Email', ['hint' => 'Another way to add custom input fields (same as using textField with type).', 'placeholder' => '*****@*****.**']);
    $f->textarea('textarea', 'Textarea');
    $f->select('select', 'Select', FormOptions::fromArray(['A', 'B', 'C']));
    $f->staticValue('static', 'Static text');
    $f->link('link', 'https://example.net', 'Static link');
    $f->hint('static', 'Lorem ipsum dot sit amet.');
    $f->uploadField('upload', 'File upload', ['remove' => true]);
    $f->checkbox('checkbox', 'Checkbox');
    $f->manual('manual', 'Manual', '<em>Custom html</em>', false);
    $f->submit('Submit button');
    $f->button('Generic button', false, ['class' => 'btn-success']);
    /* groups allows you to put multiple fields inline (label is optional) */
    $f->group('Inline group', function ($f) {
        $f->button('Button 1', false, ['class' => 'btn-default']);
        $f->button('Button 2', false, ['class' => 'btn-danger']);
        $f->button('Button 3');
    });
    /* fieldsets */
    $f->fieldset('Fieldset', function ($f) {
        $f->textField('text1', 'Input 1');
        $f->textField('text2', 'Input 2');
Пример #4
0
 /**
  * @expectedException PHPUnit_Framework_Error
  */
 public function testInvalidLabel()
 {
     $mock = new MockLayout();
     $form = Form::create('id', function ($f) {
         $f->select('foo', 5, FormOptions::fromArray([]));
     }, ['layout' => $mock]);
 }