PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, February 19, 2022

[FIXED] Error when add CSRF token to Laravel form

 February 19, 2022     laravel, laravel-5     No comments   

Issue

I have a login form in Laravel:

<form class="form-signin" action="{{ URL::route('adminAuthen') }}" method="POST">
    {{ csrf_field() }}
    <h2 class="form-signin-heading">Admin Login</h2>
    <label for="inputUsername" class="sr-only">Email address</label>
    <input type="text" id="inputUsername" name="username" class="form-control" placeholder="Username" required autofocus>
    <label for="inputPassword" class="sr-only">Password</label>
    <input type="password" id="inputPassword" name="password" class="form-control" placeholder="Password" required>
    <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>

But I always got error when visit this form:

Call to undefined function csrf_field()

How can I fix this bug?


Solution

I think there is no function called csrf_field() in laravel 5, use this instead of that.

<input type="hidden" name="_token" value="{{ csrf_token() }}">

Update 2016-03-17

Laravel introduce csrf_field() in version 5.1

{{ csrf_field() }} this will generate csrf token field,



Answered By - Kalhan.Toress
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing