简体   繁体   中英

create a form in zend framework

I want to create a form like this in Zend Framework :

<form action="some action" method="post">
    <div class="login_form">
        <h3>Admin Login</h3>
        <ul>
            <li class="login_user">
                <input type="text" name="username" value="" />
            </li>
            <li class="login_pass">
                <input type="password" name="password" value="" />
            </li>  
        </ul>
    </div>
    <input type="submit" class="login_btn blue_lgel" name="submit" value="Login" />
</form>

How can i make it possible using zend_form class?? I am just new to the zend framework.

Please, have a look at the documentation:

http://framework.zend.com/manual/1.12/en/zend.form.quickstart.html

That's what it's for: it's written to answer questions like yours.

Your code will look something like:

class MyForm extends Zend_Form
{
    public function init()
    {
        $this->setAction('/myUrl')
             ->setMethod('post');

        $this->addElement('text', 'username', array('required' => true));
        $this->addElement('password', 'passw', array('required' => true));
    }
}

Then in your controller's action:

public function myAction()
{
    $this->view->myForm = new MyForm();
}

And in your view:

<?php echo $this->myForm; ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM