php - Laravel 4 - 一个表单中的两个提交按钮,并且两个提交都由不同的操作处理

标签 php laravel laravel-4

我有一个包含电子邮件和密码字段的登录表单。我有两个提交按钮,一个用于登录(如果用户已经注册),另一个用于注册(用于新用户)。由于登录操作和注册操作不同,因此我需要某种方法将带有所有发布数据的请求重定向到其各自的操作。有没有办法在 Laravel 4 中以纯 Laravel 的方式实现这一点?

最佳答案

我的做法

如果您的表单是(2 个按钮):

{{ Form::open(array('url' => 'test/auth')) }}
{{ Form::email('email') }}
{{ Form::password('password') }}
{{ Form::password('confirm_password') }}
<input type="submit" name="login" value="Login">
<input type="submit" name="register" value="Register">
{{ Form::close() }}

创建一个 Controller 'TestController'

添加路线

Route::post('test/auth', array('uses' => 'TestController@postAuth'));

TestController 中,您有一种方法可以检查点击了哪个提交,还有两种方法用于登录和注册

<?php

class TestController extends BaseController {

    public function postAuth()
    {
        //check which submit was clicked on
        if(Input::get('login')) {
            $this->postLogin(); //if login then use this method
        } elseif(Input::get('register')) {
            $this->postRegister(); //if register then use this method
        }

    }    

    public function postLogin()
    {
        echo "We're logging in";
        //process your input here Input:get('email') etc.
    }

    public function postRegister()
    {
        echo "We're registering";
        //process your input here Input:get('email') etc.
    }

}
?>

关于php - Laravel 4 - 一个表单中的两个提交按钮,并且两个提交都由不同的操作处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20932543/

相关文章:

php - 循环遍历多维对象的递归PHP函数

php : convert serialized to array

php - 如何删除php中标签之间的文本?

Laravel 用() 消息重定向返回

php - 使用 Laravel Eloquent 关系(一对多)返回 NULL

php - 在 Eloquent 地自动获取时重命名关系名称

php - 将MySQL请求结果放入表中

php - 使用 Laravel 隐藏和显示特定 div 而不使用 jquery 的最佳方法是什么?

Laravel 社交名流 400 错误请求响应

php - Laravel 搜索属于