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; }
use FormObject\Field\Action; use FormObject\Field\CheckboxField; use FormObject\Field\BooleanRadioField; use FormObject\Field\SelectFlagsField; use FormObject\Validator\SimpleValidator; use FormObject\Validator\TextValidator; use FormObject\Validator\BooleanValidator; use FormObject\Validator\RequiredValidator; use FormObject\Validator\ValidationException; /** * @brief ... * @var \FormObject\Form */ $form = Form::create(); $flagItems = ['swimming', 'snowboarding', 'music', 'theater']; $flagsField = SelectFlagsField::create('interests', 'Interests')->setSrc($flagItems)->setValue(12); $form->push(TextField::create('name')->setTitle('Please enter your name')->setValue('Billy'), TextField::create('surname')->setTitle('Please enter your surname')->setValue('Talent'), $flagsField); $nameValidator = new TextValidator(); $nameValidator->required = FALSE; $nameValidator->minLength = 3; $nameValidator->setMaxLength = 12; $surnameValidator = new RequiredValidator(); $surnameValidator->required = TRUE; $validator = new SimpleValidator($form); $validator->set('name', $nameValidator); $validator->set('surname', $surnameValidator); $form->setValidator($validator); $data = array(); try { $data = $form->getData(); // Continue here