Beispiel #1
0
 public function createFields()
 {
     $fields = parent::createFields();
     $name = new TextField('name', 'Please enter your name');
     $name->setValue('Jennifer');
     $name->minLength = 3;
     $name->maxLength = 12;
     $surname = new TextField('surname', 'Please enter your surname');
     $surname->setValue('Batten');
     $rememberMe = new CheckboxField('remember', 'Remember Me');
     $rememberMyRadio = new BooleanRadioField('rememberMyRadio');
     $rememberMyRadio->trueString = 'Remember my Radio';
     $rememberMyRadio->falseString = 'Forget my Radio';
     $rememberMyRadio->setValue(TRUE);
     $rememberMyRadio->mustBeTrue = TRUE;
 }
$category2 = SelectOneField::create('category2', 'User Category 2');
$category2->setSrc($categories)->setClassName('RadioButtonsField');
$grouper = new OptionGrouper(function ($grouper, $item) {
    if (in_array("{$item}", array('Customer', 'Organisation', 'Organisation'))) {
        return 'Business';
    }
    return 'Personal';
});
$grouper2 = new OptionGrouper(function ($grouper, $item) {
    if (in_array("{$item}", array('Customer', 'Organisation', 'Organisation'))) {
        return 'Business';
    }
    return 'Personal';
});
$grouper2->setTitle('Business', 'Work')->setTitle('Personal', 'Home');
$form->push(TextField::create('name')->setTitle('Please enter your name')->setValue('Billy'), TextField::create('surname')->setTitle('Please enter your surname')->setValue('Talent'), CheckboxField::create('rememberMe')->setTitle('Remember Me'), BooleanRadioField::create('rememberMyRadio')->setTitle('Remember my radio')->setStringForTrue('Remember my radio')->setStringForFalse('Forget my radio')->setValue(TRUE), TextField::create('message')->setTitle('Message')->setValue('')->setMultiLine(TRUE), SelectOneField::create('category', 'User Category')->setSrc($categories)->setGrouper($grouper), SelectOneField::create('category2', 'User Category 2')->setSrc($categories)->setGrouper($grouper2));
$nameValidator = new TextValidator();
$nameValidator->required = FALSE;
$nameValidator->minLength = 3;
$nameValidator->setMaxLength = 12;
$surnameValidator = new RequiredValidator();
$surnameValidator->required = TRUE;
$requiredValidator = new BooleanValidator();
$requiredValidator->mustBeTrue = TRUE;
$validator = new SimpleValidator($form);
$validator->set('name', $nameValidator);
$validator->set('surname', $surnameValidator);
$validator->set('rememberMyRadio', $requiredValidator);
$validator->set('message', $requiredValidator);
$form->setValidator($validator);
$data = array();
use FormObject\Field\TextField;
use FormObject\Field\Action;
use FormObject\Field\CheckboxField;
use FormObject\Field\BooleanRadioField;
use FormObject\Validator\SimpleValidator;
use FormObject\Validator\TextValidator;
use FormObject\Validator\BooleanValidator;
use FormObject\Validator\RequiredValidator;
use Illuminate\Validation\Validator;
Registry::getRenderer()->addPath(dirname(__FILE__) . '/themes/bootstrap/templates/forms');
/**
 * @brief ...
 * @var \FormObject\Form
 */
$form = Form::create();
$form->push(TextField::create('name')->setTitle('Please enter your name')->setValue('Billy'), TextField::create('surname')->setTitle('Please enter your surname')->setValue('Talent'), CheckboxField::create('rememberMe')->setTitle('Remember Me'), BooleanRadioField::create('rememberMyRadio')->setTitle('Remember my radio')->setStringForTrue('Remember my radio')->setStringForFalse('Forget my radio')->setValue(TRUE), TextField::create('message')->setTitle('Message')->setValue('')->setMultiLine(TRUE));
$nameValidator = new TextValidator();
$nameValidator->required = FALSE;
$nameValidator->minLength = 3;
$nameValidator->setMaxLength = 12;
$surnameValidator = new RequiredValidator();
$surnameValidator->required = TRUE;
$requiredValidator = new BooleanValidator();
$requiredValidator->mustBeTrue = TRUE;
$validator = new SimpleValidator($form);
$validator->set('name', $nameValidator);
$validator->set('surname', $surnameValidator);
$validator->set('rememberMyRadio', $requiredValidator);
$validator->set('message', $requiredValidator);
$form->setValidator($validator);
$form->fillByGlobals();
$renderer = new Renderer\PhpRenderer();
$renderer->addPath(dirname(__FILE__) . '/themes/bootstrap/templates/forms');
$factory = new AdapterFactorySimple();
$factory->setRenderer($renderer);
/**
 * @brief ...
 * @var \FormObject\Form
 */
$form = Form::create($factory);
$form->setMethod(Form::GET);
$name = new TextField('name', 'Please enter your name');
$name->setValue('Jennifer');
$surname = new TextField('surname', 'Please enter your surname');
$surname->setValue('Batten');
$rememberMe = new CheckboxField('remember', 'Remember Me');
$rememberMyRadio = new BooleanRadioField('rememberMyRadio');
$rememberMyRadio->trueString = 'Remember my Radio';
$rememberMyRadio->falseString = 'Forget my Radio';
$rememberMyRadio->setValue(TRUE);
$container = new FieldList('group1', 'Tab One');
$container->setSwitchable(TRUE);
$form->push($container);
$container->push($name)->push($surname)->push($rememberMe)->push($rememberMyRadio);
$container2 = new FieldList('group2', 'Tab Two');
$container2->setSwitchable(TRUE);
// $container2->push($category)->push($tagsField)->push($category2)->push($tags2);
$linkTypes = array('internal' => 'Internal', 'external' => 'External');
$selectGroup = SelectOneGroup::create('linkType', 'Link')->setSrc($linkTypes);
$selectGroup->setValue('internal');
$targets = array('firstchild' => 'First Child Page', '1' => 'Home', '2' => 'Contact', '3' => 'About us');
$pages = SelectOneField::create('internalTarget', 'Target')->setSrc($targets);