开发者

Zend Famework how to set action for a form (to validate on the same page) that appears in all pages

开发者 https://www.devze.com 2023-01-27 23:08 出处:网络
I have a form (login form) that appears in all pages (if the user is not logged in开发者_运维知识库).

I have a form (login form) that appears in all pages (if the user is not logged in开发者_运维知识库).

Zend Famework how to set action for a form (to validate on the same page) that appears in all pages

The form is created from view helper and then directly called in layout.phtml

class Zend_View_Helper_LoginForm extends Zend_View_Helper_Abstract
{
public function loginForm()
{

    $login = new Application_Form_Login();
    return $login;

}

}    


<?php if(!$this->isLoggedIn()): ?>          
        <div id="login">
            New User? <a href="#">Register Here</a>
            <?php echo $this->loginForm(); ?>
            <a href="#">Forgot Password!</a>
        </div>
        <?php endif; ?>

Now how to set the action of this form such that i could validate the fields in the same page?


Matthew Weier O'Phinney (the ZF Programmer leader ) has a blogpost about creating your reusable widget exactly like your needs

you should try it ,

http://weierophinney.net/matthew/archives/246-Using-Action-Helpers-To-Implement-Re-Usable-Widgets.html


You can validate it on other page and redirect back after validation. Also, you can validate it through ajax.


What we usually do is that we send the form to different action and have dedicated form rendered in that actions view. If there is no error, user is redirected without noticing. If there is an error, the form is dispalyed in main content area with proper error messages. Usualy the problem is that the area of this form vidget is not big enough for good error message.


usually you post it to login page and if you fail you can redirect user back, set proper http header and display a error message

0

精彩评论

暂无评论...
验证码 换一张
取 消