public function __construct(Form $form, $name, $type = self::TEXT, $label = null, $labelPosition = self::LABEL_BEFORE) { $name = Strings::stringToUnderScore($name); $this->_name = $name; $this->_id = $form->getId() . '-' . Strings::urlize($name); $this->setOption('name', $name); $this->setOption('id', $this->_id); $this->_type = $type; $this->_label = $label === null ? Strings::humanize($name) : $label; $this->_labelPosition = $labelPosition; $this->_form = $form; }
public function renderElements(Form $form) { $return = ''; if ($this->_elementGroupType !== null) { $return = '<' . $this->_elementGroupType . '>'; } foreach ($form->getElements() as $element) { $return .= $element->render(); } if ($this->_elementGroupType !== null) { $return .= '</' . $this->_elementGroupType . '>'; } return $return; }
public function testFromClass() { $user = new User(); $form = Form::fromClass($user); $form->hydrate(['username' => 'myuser', 'password' => 'test', 'null_value' => '', 'emptyValue' => '']); $this->assertEquals('myuser', $form->getValue('username')); $this->assertSame(null, $form->getValue('nullValue')); $this->assertSame('', $form->getValue('emptyValue')); }