2014-04-01 175 views
1

所以,我开始与laravel。尝试将表单发布到同一页面。 这里是我到目前为止,Laravel发布:路由问题

routes.php文件

Route::get('/', '[email protected]'); 

Route::group(array('before' => 'csrf'), function() { 
    Route::post('contactus', '[email protected]'); 
}); 

hello.php

<?php echo Form::open(array('action' => '[email protected]'))?> 
input fields here 
<?php echo Form::close() ?> 

的HomeController

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

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

问题:表被张贴到URL 公共/联系我们

有人能指出其真正愚蠢的事情,我在做什么?

+0

“Laravel岗位:总新手” 不是一个问题,请大家指正与meaningfull标题你的问题。 – mpm

+0

更新了问题。 –

回答

2

routes.php文件

Route::get('/', '[email protected]'); 

Route::post('/', array(
    'before' => 'csrf', // csrf filter 
    'uses' => '[email protected]' // the controller action to be used 
)); 

hello.php

<?php echo Form::open(array('action' => '[email protected]')) ?> 
     <!-- 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

路线

Route::get('/', '[email protected]'); 
Route::post('/', '[email protected]'); 

Hello.blade.php

@if(isset($post)) 
    {{$post}} 
@endif 
{{Form::open()}} 
{{Form::text('sometext')}} 
{{Form::close()}} 

的HomeController

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

public function sendEmail() 
{ 

$post = Input::all(); 
return View::make('hello', array('post' => $post)); 
} 
+0

@Winstar - 页面刚刚重新加载。 ** **头 请求URL:http://本地主机/测试/巨大的/公共 请求方法:POST 状态代码:301永久移动 –

+0

@SwarajGiri您应该使用刀片为你的PHP文件(只是改名字)。我编辑所以你应该看到你的发布数据 – Wistar

+0

@Winstar - 不,仍然是相同的标题 –