php 在 Laravel 中获取表单输入值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29814209/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting the Form input value in Laravel
提问by ThomasMcDonald
Are there other ways to get value of an <input>
in laravel besides Input::get('name');
?
<input>
除了在 laravel 中,还有其他方法可以获取 an 的值Input::get('name');
吗?
Here is my route that tries and get the value
这是我尝试获取价值的路线
Route::get('delete_comment_action/{id}', function($id)/
{
$status_Id = Input::get('status_Id');
print_r($status_Id);
exit();
return Redirect::back();
});
here is the form that should have the data in it
这是应该包含数据的表单
<form action="" method="get">
<input type="hidden" name ="status_Id" value="{{$swagger->status_Id}}">
<a href ="{{{ url("delete_comment_action/$swagger->Id") }}}"><button type="button" class="btn btn-danger">Delete</button></a>
</form>
Status_Id should at least equal 1, when i try using, but instead it just displays a blank page.
当我尝试使用时,Status_Id 应该至少等于 1,但它只显示一个空白页面。
$variable = Input::get('status_Id');
print_r($variable);
回答by kamlesh.bar
your routes looks okay but change form submit tag instead link
您的路线看起来不错,但更改表单提交标签而不是链接
Route::get('delete_comment_action/{id}', function($id){
$status_Id = Input::get('status_Id');
print_r($status_Id);
exit();
return Redirect::back();
});
In Form view change form action and replace anchor tag link with submit button
在表单视图中更改表单操作并用提交按钮替换锚标记链接
<form action="{{{ url("delete_comment_action/$swagger->Id") }}}" method="get">
<input type="hidden" name ="status_Id" value="{{$swagger->status_Id}}">
<input type="submit" value="Delete">
</form>
回答by Set Kyar Wa Lar
You are trying to use same route twice. You can't use it. What you have to do is separate routes like the following
您正尝试使用相同的路线两次。你不能使用它。您需要做的是如下所示的单独路线
This route is to show view
这条路线是为了显示视图
Route::get('test', function() {
return View::make('example');
});
This route will handle when you submit your form
当您提交表单时,此路由将处理
Route::get('newtest', function() {
dd(Input::all());
});
In your example.blade.php
在你的 example.blade.php
<form action="" method="get">
<input type="text" name="hello">
<input type="submit" value="Submit">
</form>