所以,我从laravel开始。尝试将表格发布到同一页面。 这是我到目前为止所拥有的,
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;
}
问题:表单会发布到网址 public / contactus
有人可以指出我正在做哪些非常愚蠢的事情吗?
答案 0 :(得分:2)
<强> 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 :(得分:-1)
路线
Route::get('/', 'HomeController@showWelcome');
Route::post('/', 'HomeController@sendEmail');
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));
}