<?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']);
public function testUnbufferedObject() { $obj = (object) ['id' => 7, 'foo' => 'spam']; ob_start(); Form::fromObject($obj, function ($f) { $f->textField('foo', 'Test field', ['type' => 'email']); }, ['layout' => 'unbuffered']); $this->html = ob_get_contents(); ob_end_clean(); $this->validate([['form_start'], ['input', ['type' => 'hidden', 'name' => 'stdClass[id]', 'value' => 7]], ['label_start', ['for' => 'stdClass_7_foo']], ['content', 'Test field'], ['label_end'], ['input', ['type' => 'email', 'name' => 'stdClass[foo]', 'id' => 'stdClass_7_foo']], ['form_end']]); }
public function testFromObjectButtonName() { $mock = new MockLayout(); $data = (object) ['foo' => 'bar']; $form = Form::fromObject($data, function ($f) { $f->button('Label', 'foo'); $f->submit('Label', 'bar'); }, ['layout' => $mock]); $this->assertArrayHasKey('foo', $mock->field, "Buttons should always be unprefixed"); $this->assertArrayHasKey('bar', $mock->field, "Buttons should always be unprefixed"); }