在Laravel中获取表单输入值

时间:2015-04-23 05:10:39

标签: php laravel blade

除了<input>之外,是否还有其他途径可以获得Input::get('name'); laravel的价值?

这是尝试获取值的路线

Route::get('delete_comment_action/{id}', function($id)/
{

    $status_Id = Input::get('status_Id');
    print_r($status_Id);
    exit();

    return Redirect::back();
});

这里应该包含数据的表单

<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应该至少等于1,而是只显示一个空白页面。

$variable = Input::get('status_Id'); 

print_r($variable);

2 个答案:

答案 0 :(得分:6)

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>

答案 1 :(得分:0)

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

<form action="" method="get">
     <input type="text" name="hello">
     <input type="submit" value="Submit">
</form>