将 HTML 占位符添加到 Zend_Form [英] Add HTML placeholder into Zend_Form

查看:24
本文介绍了将 HTML 占位符添加到 Zend_Form的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Zend_Form 用于使用此代码的申请表:

class Form_ApplicationForm 扩展 Zend_Form{公共函数 init(){$this->setAction('/application/new')->setMethod('post')-> setAttrib('id','application');$name = new Zend_Form_Element_Text('name');$name->setLabel('你的名字')->setRequired(TRUE)->addValidator('alpha', FALSE, array('allowWhiteSpace' => true));$email = new Zend_Form_Element_Text('email');$email->setLabel('电子邮件地址')->setRequired(TRUE)->addValidator('EmailAddress');$this->addElements(array($name,$email));}}

我正在向这个表单添加一个 Flash 文件上传器 (swfupload),它需要一个 HTML 片段才能工作,片段如下所示:

<p>上传最多 5 个图像文件(jpg、png、gif),每个文件的最大大小为 1MB(使用 Ctrl/Shift 选择多个文件)</p><input type="button" id="button"/><p id="队列状态" ></p><ol id="日志"></ol>

插入它以便它位于<form>中的某个位置的最佳方法是什么,我正在像这样插入我的控制器中:

公共函数 newAction(){$form = new Form_ApplicationForm();if($this->_request->isPost()){$data = $_POST;if($form->isValid($data)){///在这里处理数据}别的{$form->populate($data);}}$this->view->form = $form;}

有没有办法在 Zend_Form 中添加占位符或类似的东西,还是应该使用装饰器或类似的东西来完成?

谢谢.

解决方案

您必须为此编写自己的元素,例如My_Form_Element_SwfUpload 以及渲染器.请参阅这些教程:

I'm using Zend_Form for an application form using this code:

class Form_ApplicationForm extends Zend_Form
{
    public function init()
    {
        $this->setAction('/application/new')
             ->setMethod('post')
             ->setAttrib('id','application');

        $name = new Zend_Form_Element_Text('name');
        $name->setLabel('Your Name')
             ->setRequired(TRUE)
             ->addValidator('alpha', FALSE, array('allowWhiteSpace' => true));

        $email = new Zend_Form_Element_Text('email');
        $email->setLabel('Email Address')
              ->setRequired(TRUE)
              ->addValidator('EmailAddress');

        $this->addElements(array($name,$email));
    }
}

I'm adding a flash file uploader (swfupload) to this form which needs a HTML snippet to be in place to work, the snippet looks like this:

<div id="swfupload-control">
    <p>Upload upto 5 image files(jpg, png, gif), each having maximum size of 1MB(Use Ctrl/Shift to select multiple files)</p>
    <input type="button" id="button" />
    <p id="queuestatus" ></p>
    <ol id="log"></ol>
</div>

What is the best way of inserting this so that it sits somewhere within the <form> which i'm inserting within my controller like this:

public function newAction()
{
    $form = new Form_ApplicationForm();
    if($this->_request->isPost()){
        $data = $_POST;
        if($form->isValid($data)){
            /// handle data here
        }else{
            $form->populate($data);
        }
    }
    $this->view->form = $form;
}

Is there a way of adding a placeholder or similar within Zend_Form, or should this be done using a decorator or something like that?

Thanks.

解决方案

You'd have to write your own Element for this, e.g. My_Form_Element_SwfUpload along with a renderer. See these tutorials:

这篇关于将 HTML 占位符添加到 Zend_Form的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆