首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CakePHP -在同一页上具有不同操作的多个表单

CakePHP -在同一页上具有不同操作的多个表单
EN

Stack Overflow用户
提问于 2011-07-26 01:07:06
回答 1查看 5.5K关注 0票数 0

我的主页上有两个不同的表单,一个用于注册用户,另一个用于登录。这两种形式指向相同的模型,但指向不同的操作。问题是,如果你提交任何一个表单,它也会触发另一个表单上的操作,所以如果我试图登录,它会在控制器中触发注册操作,例如,就像我试图注册一样。

我已经检查过this solution了,但对于这么简单的东西,它似乎太复杂了,更不用说它会把我的models文件夹中的额外模型弄得乱七八糟,除了一个单独的操作之外,这些模型几乎没有用。

编辑:我的项目中没有Auth下的这一部分,我在Auth下设置了管理路由和管理部分,但在非管理部分,我使用了自己的会话处理和用户验证。

下面是我的表单的代码:

这是注册表:

代码语言:javascript
复制
echo $this->Form->create('Fonyker', array('action' => 'add'));
            echo $this->Form->input('username', array(
                'div' => array(
                    'class' => 'span-8'
                ),
                'class' => 'input-text long',
                'id' => 'FonykerUsernameRegister',
                'label' => array(
                    'class' => 'inlined',
                    'text' => ''
                ),
                'placeholder' => 'Username',
                'onsubmit' => 'return false;'
            ));
            echo $this->Form->input('email', array(
                'div' => array(
                    'class' => 'span-8'
                ),
                'class' => 'input-text long',
                'label' => array(
                    'class' => 'inlined',
                    'text' => ''
                ),
                'placeholder' => 'Email',
                'onsubmit' => 'return false;'
            ));
            echo $this->Form->input('password', array(
                'div' => array(
                    'class' => 'span-8'
                ),
                'class' => 'input-text long',
                'id' => 'FonykerPasswordRegister',
                'label' => array(
                    'class' => 'inlined',
                    'text' => ''
                ),
                'placeholder' => 'Password',
                'onsubmit' => 'return false;'
            ));
            echo $this->Form->input('name', array(
                'div' => array(
                    'class' => 'span-8'
                ),
                'class' => 'input-text long',
                'label' => array(
                    'class' => 'inlined',
                    'text' => ''
                ),
                'placeholder' => 'Name',
                'onsubmit' => 'return false;'
            ));
        ?>
        <div class="span-8 required">
            <label for="FonykerBirthdate" class="inlined">From</label>
            <input id="FonykerBirthdate" type="text" onsubmit="return false;" placeholder="Birthdate" name="data[Fonyker][birthdate]" class="datepicker input-text long" enabled="false">
        </div>
        <?php

            $options = array('M' => 'M', 'F' => 'F');
            $attributes = array(
                'empty' => 'Gender',
                'class' => 'input-combo span-8'
            );

            echo $this->Form->select('gender', $options, NULL, $attributes);

            echo $this->Form->submit('',array(
                'class' => 'signup-button', 
                'id' => 'signup-button'
            ));

            echo $this->Form->end();
        ?>

和登录表单:

代码语言:javascript
复制
echo $this->Form->create('Fonyker', array('action' => 'login'));
                    echo $this->Form->input('username', array(
                        'div' => array(
                            'class' => 'span-3'
                        ),
                        'class' => 'input-text short',
                        'id' => 'FonykerUsernameLogin',
                        'label' => array(
                            'class' => 'inlined',
                            'text' => ''
                        ),
                        'placeholder' => 'Username'
                    ));
                    echo $this->Form->input('password', array(
                        'div' => array(
                            'class' => 'span-3',
                        ),
                        'class' => 'input-text short',
                        'id' => 'FonykerPasswordLogin',
                        'label' => array(
                            'class' => 'inlined',
                            'text' => ''
                        ),
                        'placeholder' => 'Password'
                    ));

                    echo $this->Form->submit('',array(
                        'div' => array(
                            'class' => 'span-1'
                        ),
                        'class' => 'login-button', 
                    ));

                    echo $this->Form->input('Fonyker.remember', array(
                        'div' => array(
                            'class' => 'span-3',
                        ),
                        'type' => 'checkbox', 
                        'label' => array(
                            'text' => 'Remember me',
                            'style' => 'margin-left:-10px;'
                        ), 
                        'value' => 'yes',
                        'class' => 'span-1'
                    ));

                    echo $this->Html->link(__("Forgot it?", TRUE), array('controller' => "pages", 'action' => "recover_password" ), array('class' => 'span-2'));

                    echo $this->Form->end();
                ?>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-08-13 01:14:51

最后的问题只是由于我的表单的命名,如果表单和字段来自同一个控制器,您必须确保它们的名称不重叠,并确保表单正确结束。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6819791

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档