Zend:无需验证即可从表单重定向 [英] Zend: Redirect from form without validation

查看:178
本文介绍了Zend:无需验证即可从表单重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个创建新组的表单。我现在添加了一个小的返回图像,用户应该能够返回一步。我不知道为什么,但是当我单击这个新图像时,用于我想要离开的窗体( / admin / creategroup )的控制器和动作会再次使用HTTP POST集进行调用。因此,表单验证已完成,并且我被困在此表单中,并显示验证错误。

I have a form for the creation of new "groups". I now added a small "go back" image with which the user should be able to go back one step. I don't know why, but when I click this new image, the controller and action used for the form which I want to leave (/admin/creategroup) is called again with HTTP POST set. Therefore, the form validation is done, and I'm stuck at this form with the validation errors displayed.

这是我的表单中代码片段,包含图像-纽扣。我不想返回 - 图像将我重定向到指定的控制器,而未验证表单

This is a snippet of the code from my form with both image-buttons. I wan't the "go back"-image to redirect me to the specified controller without validating the form:

    $this->addElement('image', 'btnBack', array (
        'name' => 'btnBack',
        'id'   => 'btnBack',
        'label' => '',
        'title' => 'Go back',
        'alt' => 'Go back',
        'src' => '/img/undo.png',
        'onClick' => "window.location='/admin/groupoverview'"
    ));

    $this->addElement('image', 'btnSave', array (
        'name' => 'btnSave',
        'id'   => 'btnSave',
        'label' => '',
        'title' => 'Save this new group',
        'alt' => 'Save this new group',
        'src' => '/img/save.png',
        'onClick' => "document.forms[0].submit();"
    ));

编辑:

我已经想过可以签入 / admin / creategroup 无论是从'btnBack'图像还是'btnSave'图像调用,并且如果源为'btnBack'图像,都跳过表单验证并正确重定向。

我认为应该有一个更好的解决方案来直接从表单重定向,并避免再次调用 / admin / creategroup



编辑2:

我的视图脚本:


I already thought of the possibility to check in /admin/creategroup whether it was called from the 'btnBack'-image or the 'btnSave'-image and skip form validation and redirect correctly if the source was the 'btnBack'-image.
I just think that there should be a nicer solution to directly redirect from the form and circumvent calling /admin/creategroup again.


My view script:

<div id="createGroupMask">
    <br/>
    Use the form below to create a new group
    <?php
        $this->form->setAction($this->url());
        echo $this->form;
    ?>
</div>

我在控制器中的操作

My action in the controller:

public function creategroupAction()
{
    $form = new Application_Form_CreateGroup();
    $request = $this->getRequest();

    if ($request->isPost()) {
        if ($form->isValid($request->getPost())) {
            // Data for new group is valid
            ...
        } else {
            // Form data was invalid
            // => This is where I land when pressing the 'back' image
            // No further code here
        }
    }
    $this->view->form = $form;
}


推荐答案

方法在我有点相关的问题:
Zend表单:如何用超链接包围图像元素?

Tim Fountain suggested an even cleaner approach in my somewhat related question: Zend forms: How to surround an image-element with a hyperlink?

这篇关于Zend:无需验证即可从表单重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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