protected function generateKform() { $kform = new KForm(); $formfield = new Text(); $formfield->setFieldName('username'); $formfield->setLabel('请输入您的姓名(*)'); $formfield->setRules(array('required' => '请输入您的姓名', 'min:2' => '最少2个字符', 'max:10' => '最长10个字符')); $kform->addFormField($formfield); $formfield = new Password(); $formfield->setFieldName('old_password'); $formfield->setLabel('请输入您的密码(*)'); $formfield->setRules(array('required' => '必填')); $kform->addFormField($formfield); $formfield = new Text(); $formfield->setFieldName('email'); $formfield->setLabel('请输入您的邮箱(*)'); $formfield->setRules(array('required' => '必填', 'email' => '请输入合法的邮箱')); $kform->addFormField($formfield); $formfield = new Text(); $formfield->setFieldName('mobile'); $formfield->setLabel('请输入您的手机(*)'); $formfield->setRules(array('required' => '必填', 'mobile' => '请输入合法的手机')); $kform->addFormField($formfield); $formfield = new Select(); $formfield->setFieldName('gender'); $formfield->setLabel('请输入您的性别'); $formfield->setOptions(array('未填' => '未填', '男' => '男', '女' => '女')); $kform->addFormField($formfield); return $kform; }
protected function generateKform() { $form = new KForm(); $field = new Text(); $field->setFieldName('name')->setRules(array('required' => '角色名不能为空', 'min:3' => '角色名不能小于3个字符', 'max:100' => '角色名不能大于100个字符'))->setWidth(1)->setDefault(null)->setLabel('请输入角色名'); $form->addFormField($field); $field = new Text(); $field->setFieldName('display_name')->setRules(array('required' => '描述不能为空', 'min:5' => '描述不能小于5个字符', 'max:100' => '描述不能大于100个字符'))->setWidth(1)->setDefault(null)->setLabel('请输入描述'); $form->addFormField($field); return $form; }
protected function generateKform() { $kform = new KForm(); $formfield = new Password(); $formfield->setFieldName('old_password'); $formfield->setLabel('请输入您的旧密码(*)'); $formfield->setRules(array('required' => '必填')); $kform->addFormField($formfield); $formfield = new Password(); $formfield->setFieldName('password'); $formfield->setLabel('请输入您的新密码(*)'); $formfield->setRules(array('required' => '必填', 'confirmed' => '两次输入必须一致', 'min:6' => '密码长度不应小于6位', 'max:32' => '密码长度不应大于32位')); $kform->addFormField($formfield); $formfield = new Password(); $formfield->setFieldName('password_confirmation'); $formfield->setLabel('请再输入一次(*)'); $formfield->setRules(array('required' => '必填', 'min:6' => '密码长度不应小于6位', 'max:32' => '密码长度不应大于32位')); $kform->addFormField($formfield); return $kform; }
/** * @param array $config * @return KForm */ public static function build(array $config) { $form = new KForm(); foreach ($config as $name => $blueprint) { $type = $blueprint['type']; $field = new $type(); if ($field instanceof FormField) { $field->setFieldName($name); $field->setLabel($blueprint['label']); $field->setRules($blueprint['rules']); if (isset($blueprint['options'])) { $field->setOptions($blueprint['options']); } } if (isset($blueprint['width'])) { $field->setWidth($blueprint['width']); } $form->addFormField($field); } return $form; }