Home > Blockchain >  Login form is not posting
Login form is not posting

Time:06-09

I'm developing a Laravel app, and have setup a login page, but I'm trying to figure out why my login form isn't posting.

  <form role="form" method="post" action="{{ route('login.perform') }}">
    <div >
      <label >Email address</label>
      @if ($errors->has('username'))
        <span >{{ $errors->first('username') }}</span>
      @endif
      <div >
        <div >
          <span ><i ></i></span>
        </div>
        <input type="email"  id="input-email" placeholder="[email protected]">
      </div>
    </div>
    <div >
      <div >
        <div>
          <label >Password</label>
          @if ($errors->has('password'))
            <span >{{ $errors->first('password') }}</span>
          @endif
        </div>
        <div >
          <a href="#!" >Lost password?</a>
        </div>
      </div>
      <div >
        <div >
          <span ><i ></i></span>
        </div>
        <input type="password"  id="input-password" placeholder="Password">
        <div >
          <span >
            <a href="#" data-toggle="password-text" data-target="#input-password">
              <i ></i>
            </a>
          </span>
        </div>
      </div>
    </div>
    <div >
      <button type="button" >
        <span >Sign in</span>
        <span ><i ></i></span>
      </button>
    </div>
  </form>

This is the controller that handles the login request.


<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests\LoginRequest;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
    /**
     * Display login page.
     * 
     * @return Renderable
     */
    public function show()
    {
        return view('auth.login');
    }

    /**
     * Handle account login request
     * 
     * @param LoginRequest $request
     * 
     * @return \Illuminate\Http\Response
     */
    public function login(LoginRequest $request)
    {
        $credentials = $request->getCredentials();

        if(!Auth::validate($credentials)):
            return redirect()->to('login')
                ->withErrors(trans('auth.failed'));
        endif;

        $user = Auth::getProvider()->retrieveByCredentials($credentials);

        Auth::login($user);

        return $this->authenticated($request, $user);
    }

    /**
     * Handle response after user authenticated
     * 
     * @param Request $request
     * @param Auth $user
     * 
     * @return \Illuminate\Http\Response
     */
    protected function authenticated(Request $request, $user) 
    {
        return redirect()->intended();
    }
}

This is the web.php route.


<?php
  
use Illuminate\Support\Facades\Route;
 
use App\Http\Controllers\HomeController;
use App\Http\Controllers\TeacherController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\Auth\RegisterController;


/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group that
| contains the "web" middleware group. Now create something great!
|
*/
 

Route::group(['namespace' => 'App\Http\Controllers'], function()
{   
    /**
     * Home Routes
     */
    Route::get('/', 'HomeController@welcome')->name('welcome');

    Route::group(['middleware' => ['guest']], function() {
        /**
         * Register Routes
         */
        Route::get('/register', 'RegisterController@show')->name('register.show');
        Route::post('/register', 'RegisterController@register')->name('register.perform');

        /**
         * Login Routes
         */
        Route::get('/login', 'LoginController@show')->name('login.show');
        Route::post('/login', 'LoginController@login')->name('login.perform');

    });

    Route::group(['middleware' => ['auth']], function() {
        /**
         * Logout Routes
         */
        Route::get('/logout', 'LogoutController@perform')->name('logout.perform');
    });
});

The database is setup, migrated and is appearing in phpMyAdmin, routes controllers and requests are all setup correctly to my understanding.

Any help is appreciated, cheers.

CodePudding user response:

The reason why the form can't submit is that you don't have submit button, add the type="submit" to the <button> will resolve the issue:

<button type="submit" >

I read the comments, and you said the form is loaded but does not send any data. Please show how you get data in the controller, and the route also, that will help another find out the problem.

CodePudding user response:

csrf is missing in your form

Try this

<form role="form" method="post" action="{{ route('login.perform') }}">
    @csrf

    ...
  • Related