protected function getSettingFields() { $settingFields = new FieldList('settings', trans('cmsable::forms.page-form.settings')); $settingFields->setSwitchable(TRUE); $settingFields->push($this->createPageTypeField()); if ($this->hasVisibilityField()) { $options = [trans('cmsable::models.page.enums.visibility.show_in_menu'), trans('cmsable::models.page.enums.visibility.show_in_aside_menu'), trans('cmsable::models.page.enums.visibility.show_in_search'), trans('cmsable::models.page.enums.visibility.show_when_authorized')]; $settingFields->push(SelectFlagsField::create('visibility')->setTitle(trans('cmsable::models.page.fields.visibility'))->setSrc($options)); } else { $settingFields->push(CheckboxField::create('show_in_menu')->setTitle(trans('cmsable::models.page.fields.show_in_menu')), CheckboxField::create('show_in_aside_menu')->setTitle(trans('cmsable::models.page.fields.show_in_aside_menu')), CheckboxField::create('show_in_search')->setTitle(trans('cmsable::models.page.fields.show_in_search'))); } return $settingFields; }
$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();
use FormObject\Field\TextField; use FormObject\Field\PasswordField; 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; Registry::getRenderer()->addPath(dirname(__FILE__) . '/themes/bootstrap/templates/forms'); /** * @brief ... * @var \FormObject\Form */ $form = Form::create(); $form->push(TextField::create('login')->setTitle('Please enter your name')->setValue('admin'), PasswordField::create('surname')->setTitle('Please enter your surname')->setValue(''), CheckboxField::create('rememberMe')->setTitle('Remember Me')); $nameValidator = new TextValidator(); $nameValidator->required = FALSE; $nameValidator->minLength = 3; $nameValidator->setMaxLength = 12; $requiredValidator = new RequiredValidator(); $requiredValidator->required = TRUE; $trueValidator = new BooleanValidator(); $trueValidator->mustBeTrue = TRUE; $validator = new SimpleValidator($form); $validator->set('login', $nameValidator); $validator->set('surname', $requiredValidator); // $validator->set('rememberMyRadio', $trueValidator); // $validator->set('category', $requiredValidator); $form->setValidator($validator); $form->fillByGlobals();