Пример #1
0
 /**
  * 初始化当前输入项
  *
  * @access public
  * @param string $name 表单元素名称
  * @param array $options 选择项
  * @return Typecho_Widget_Helper_Layout
  */
 public function input($name = NULL, array $options = NULL)
 {
     $input = new Typecho_Widget_Helper_Layout('select');
     $this->container($input->setAttribute('name', $name)->setAttribute('id', $name . '-0-' . self::$uniqueId));
     $this->label->setAttribute('for', $name . '-0-' . self::$uniqueId);
     foreach ($options as $value => $label) {
         $this->_options[$value] = new Typecho_Widget_Helper_Layout('option');
         $input->addItem($this->_options[$value]->setAttribute('value', $value)->html($label));
     }
     return $input;
 }
Пример #2
0
 /**
  * 初始化当前输入项
  *
  * @access public
  * @param string $name 表单元素名称
  * @param array $options 选择项
  * @return Typecho_Widget_Helper_Layout
  */
 public function input($name = NULL, array $options = NULL)
 {
     foreach ($options as $value => $label) {
         $this->_options[$value] = new Typecho_Widget_Helper_Layout('input');
         $item = $this->multiline();
         $item->addItem($this->_options[$value]->setAttribute('name', $this->name . '[]')->setAttribute('type', 'checkbox')->setAttribute('value', $value)->setAttribute('id', $this->name . '-' . $value));
         $labelItem = new Typecho_Widget_Helper_Layout('label');
         $item->addItem($labelItem->setAttribute('for', $this->name . '-' . $value)->html($label));
         $this->container($item);
     }
     return current($this->_options);
 }
Пример #3
0
 public static function form($action = NULL)
 {
     /** 构建表格 */
     $options = Typecho_Widget::widget('Widget_Options');
     $form = new Typecho_Widget_Helper_Form(Typecho_Common::url('/action/huifeng-members-edit', $options->index), Typecho_Widget_Helper_Form::POST_METHOD);
     $form->setAttribute('enctype', 'multipart/form-data');
     // 表示可以上传数据
     /* 添加隐藏域限制上传大小 */
     $maxfilesize = new Typecho_Widget_Helper_Form_Element_Hidden('MAX_FILE_SIZE', NULL, '1000000', NULL, NULL);
     $form->addInput($maxfilesize);
     // 限制大小的隐藏域应在上传标签之前
     /** 头像 */
     $image_upload = new Typecho_Widget_Helper_Form_Element_Text('image_upload', NULL, NULL, _t('上传头像'), NULL);
     // 用于头像图片上传
     $image_upload->input->setAttribute('type', 'file');
     $image = new Typecho_Widget_Helper_Form_Element_Text('image', NULL, NULL, _t('头像'), NULL);
     // 获取数据库里的头像地址
     $img_show = new Typecho_Widget_Helper_Layout('img', NULL);
     $img_src = '/usr/plugins/HuifengMembers/nopic.jpg';
     if ($image->getAttribute('src' != '')) {
         $img_src = $image->getAttribute('src');
     }
     $img_show->setAttribute('src', $img_src);
     $img_show->setAttribute('height', '180');
     $img_show->setAttribute('style', 'margin-top: 4em;max-width: 180px;max-height: 180px;');
     $form->addItem($img_show);
     $form->addInput($image_upload);
     $form->addInput($image);
     /** 会员名称 */
     // Typecho_Widget_Helper_Form_Element_Text ($name=NULL, array $options=NULL, $value=NULL, $label=NULL, $categories=NULL)
     $name = new Typecho_Widget_Helper_Form_Element_Text('name', NULL, NULL, _t('会员名称*'), _t('请填写真实姓名'));
     $form->addInput($name);
     /** 所在部门 */
     $position = new Typecho_Widget_Helper_Form_Element_Text('position', NULL, NULL, _t('所在部门*'), _t('请正确填写所在部门科室'));
     $form->addInput($position);
     /** 联系电话 */
     $tel = new Typecho_Widget_Helper_Form_Element_Text('tel', NULL, NULL, _t('联系电话'), NULL);
     $form->addInput($tel);
     /** 分类 */
     $categories = new Typecho_Widget_Helper_Form_Element_Text('categories', NULL, NULL, _t('分类'));
     $form->addInput($categories);
     /** 是否值班 */
     $is_onduty = new Typecho_Widget_Helper_Form_Element_Radio('is_onduty', array('否' => _t('否'), '是' => _t('是')), '否', _t('是否值班'));
     $form->addInput($is_onduty);
     /** 自定义数据 */
     $field = new Typecho_Widget_Helper_Form_Element_Text('field', NULL, NULL, _t('自定义数据'), _t('该项用于用户自定义数据扩展'));
     $form->addInput($field);
     /** 会员动作 */
     $do = new Typecho_Widget_Helper_Form_Element_Hidden('do');
     $form->addInput($do);
     /** 会员主键 */
     $mid = new Typecho_Widget_Helper_Form_Element_Hidden('mid');
     $form->addInput($mid);
     /** 提交按钮 */
     $submit = new Typecho_Widget_Helper_Form_Element_Submit();
     $submit->input->setAttribute('class', 'btn primary');
     $form->addItem($submit);
     $request = Typecho_Request::getInstance();
     if (isset($request->mid) && 'insert' != $action) {
         /** 更新模式 */
         $db = Typecho_Db::get();
         $prefix = $db->getPrefix();
         $member = $db->fetchRow($db->select()->from($prefix . 'hf_members')->where('mid = ?', $request->mid));
         if (!$member) {
             throw new Typecho_Widget_Exception(_t('会员不存在'), 404);
         }
         $name->value($member['name']);
         $position->value($member['position']);
         $tel->value($member['tel']);
         $image->value($member['image']);
         $categories->value($member['categories']);
         $is_onduty->value($member['is_onduty']);
         $field->value($member['field']);
         $do->value('update');
         $mid->value($member['mid']);
         $submit->value(_t('编辑会员'));
         $_action = 'update';
     } else {
         $do->value('insert');
         $submit->value(_t('增加会员'));
         $_action = 'insert';
     }
     if (empty($action)) {
         $action = $_action;
     }
     /** 给表单增加规则 */
     if ('insert' == $action || 'update' == $action) {
         $name->addRule('required', _t('必须填写会员名称'));
         $name->addRule('xssCheck', _t('请勿在会员名称栏输入特殊字符'));
         $position->addRule('required', _t('必须填写所在部门'));
         $position->addRule('xssCheck', _t('请勿在所在部门栏输入特殊字符'));
         // $position->addRule('url', _t('不是一个合法的url'));
         // $image->addRule('image', _t('不是一个合法的图片地址'));
         $tel->addRule('required', _t('必须填写联系电话'));
         $tel->addRule('isInteger', _t('电话号码必须是无符号整数'));
         $tel->addRule('minLength', _t('电话号码不得小于6位'), 6);
         $tel->addRule('maxLength', _t('电话号码不得大于11位'), 12);
         // $image->addRule('required', _t('必须上传头像图片'));
     }
     if ('update' == $action) {
         $mid->addRule('required', _t('会员主键不存在'));
         $mid->addRule(array(new HuifengMembers_Plugin(), 'HuifengMembersExists'), _t('会员不存在'));
     }
     return $form;
 }
Пример #4
0
 public function input($name = NULL, array $options = NULL)
 {
     $input = new Typecho_Widget_Helper_Layout('select', array('onchange' => 'select_theme_change(this);'));
     $this->container($input->setAttribute('name', $name)->setAttribute('id', $name . '-0-' . self::$uniqueId));
     $this->label->setAttribute('for', $name . '-0-' . self::$uniqueId);
     $this->inputs[] = $input;
     foreach ($options as $value => $label) {
         $this->_options[$value] = new Typecho_Widget_Helper_Layout('option');
         $input->addItem($this->_options[$value]->setAttribute('value', $value)->html($label));
         if (DomainTheme_Plugin::$TEMP_THEME_NAME == $value) {
             $this->_options[$value]->setAttribute('selected', 'selected');
         }
     }
     return $input;
 }