コード例 #1
0
ファイル: Edit.php プロジェクト: menmenweiwei/blog
 /**
  * 生成表单
  *
  * @access public
  * @param string $action 表单动作
  * @return Typecho_Widget_Helper_Form_Element
  */
 public function form($action = NULL)
 {
     /** 构建表格 */
     $form = new Typecho_Widget_Helper_Form(Typecho_Common::url('/action/contents-attachment-edit', $this->options->index), Typecho_Widget_Helper_Form::POST_METHOD);
     /** 文件名称 */
     $name = new Typecho_Widget_Helper_Form_Element_Text('name', NULL, $this->title, _t('标题 *'));
     $form->addInput($name);
     /** 文件缩略名 */
     $slug = new Typecho_Widget_Helper_Form_Element_Text('slug', NULL, $this->slug, _t('缩略名'), _t('文件缩略名用于创建友好的链接形式,建议使用字母,数字,下划线和横杠.'));
     $form->addInput($slug);
     /** 文件描述 */
     $description = new Typecho_Widget_Helper_Form_Element_Textarea('description', NULL, $this->attachment->description, _t('描述'), _t('此文字用于描述文件,在有的主题中它会被显示.'));
     $form->addInput($description);
     /** 分类动作 */
     $do = new Typecho_Widget_Helper_Form_Element_Hidden('do', NULL, 'update');
     $form->addInput($do);
     /** 分类主键 */
     $cid = new Typecho_Widget_Helper_Form_Element_Hidden('cid', NULL, $this->cid);
     $form->addInput($cid);
     /** 提交按钮 */
     $submit = new Typecho_Widget_Helper_Form_Element_Submit(NULL, NULL, _t('提交修改'));
     $submit->input->setAttribute('class', 'primary');
     $delete = new Typecho_Widget_Helper_Layout('a', array('href' => Typecho_Common::url('/action/contents-attachment-edit?do=delete&cid=' . $this->cid, $this->options->index), 'class' => 'operate-delete', 'lang' => _t('你确认删除文件 %s 吗?', $this->attachment->name)));
     $submit->container($delete->html(_t('删除文件')));
     $form->addItem($submit);
     $name->addRule('required', _t('必须填写文件标题'));
     $name->addRule(array($this, 'nameToSlug'), _t('文件标题无法被转换为缩略名'));
     $slug->addRule(array($this, 'slugExists'), _t('缩略名已经存在'));
     return $form;
 }