Problem with Form

25 views
Skip to first unread message

Belmar Santanilla Gutiérrez

unread,
Mar 6, 2014, 10:20:40 PM3/6/14
to lar...@googlegroups.com
Dear friends! 

Today I doubt, I am following an example of Laravel CookBook and have the following code: 

View:
@extends("layout")
@section("content")
       {{ Form::open(['route'=>'user/login', 'autocomplete'=>'off']) }}
       {{ Form::label("username", "Username") }}
       {{ Form::text("username", "", ["placeholder"=>"john.smith"]) }}
       {{ Form::label("password", "Password") }}
       {{ Form::password("password", ["placeholder"=>"********"]) }}
       @if($error = $errors->first("password"))
       <div class="error">
               {{ $error }}
       </div>
       @endif        
       {{ Form::submit("login") }}
       {{ Form::close() }}
@stop
@section("footer")
       @parent
       <script src="//polyfill.io"></script>
@stop

Controller:
       public function loginAction(){
               $data = [];                
               if(Input::server("REQUEST_METHOD") == "POST"){
                       $validator = Validator::make(Input::all(), [
                               "username" => "required",
                               "password" => "required"
                       ]);

                       if($validator->passes()){
                               echo "El Usuario se ha logueado";
                       }
                       else{
                               $data["errors"] = new MessageBag([
                                       "password" => [
                                               "Username and/or password Invalid"
                                       ]
                               ]);
                       }
               }
               return View::make("user/login", $data);
       }

And routes:
Route::any('/', [
       "as" => "user/login",
       "uses" => "UserController@loginAction"
]);

The problem is when I send the form data does not validate me and is basically because although the POST form is always comes as GET to submit the form. 
Reply all
Reply to author
Forward
0 new messages