dongyihao9887 2014-04-01 06:46
浏览 35
已采纳

Laravel帖子:路由问题

So, i started with laravel. Tried with making a form post to the same page. Here's what i have so far,

routes.php

Route::get('/', 'HomeController@showWelcome');

Route::group(array('before' => 'csrf'), function () {
   Route::post('contactus', 'HomeController@sendEmail');
});

hello.php

<?php echo Form::open(array('action' => 'HomeController@sendEmail'))?>
input fields here
<?php echo Form::close() ?>

HomeController

public function showWelcome()
{
    return View::make('hello');
}

public function sendEmail()
{
    print_r($_POST);exit;
}

Problem: Form gets posted to the url public/contactus

Can someone point out which really stupid thing, i am doing?

  • 写回答

2条回答 默认 最新

  • donk68254 2014-04-01 08:01
    关注

    routes.php

    Route::get('/', 'HomeController@showWelcome');
    
    Route::post('/', array(
        'before' => 'csrf',  // csrf filter
        'uses' => 'HomeController@sendEmail' // the controller action to be used
    ));
    

    hello.php

    <?php echo Form::open(array('action' => 'HomeController@sendEmail')) ?>
          <!-- input fields here -->
    <?php echo Form::close() ?>
    

    HomeController.php

    Public function showWelcome()
    {
        return View::make('hello');
    }
    
    public function sendEmail()
    {
        $data = Input::all();
        print_r($data);
        // return the same view but with posted fields in the $data array
        return View::make('hello', $data);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部