Adding form action in html in laravel

前端 未结 12 1225
深忆病人
深忆病人 2020-12-29 21:10

I am unable to pass url in views html form action tag.

相关标签:
12条回答
  • 2020-12-29 21:37

    For Laravel 2020. Ok, an example:

    <form class="modal-content animate" action="{{ url('login_kun')  }}" method="post">
      @csrf   // !!! attention - this string is a must 
    ....
     </form>
    

    And then in web.php:

    Route::post("/login_kun", "LoginController@login");
    

    And one more in new created LoginController:

     public function login(Request $request){
        dd($request->all());
    }
    

    and you are done my friend.

    0 讨论(0)
  • 2020-12-29 21:40
    {{ Form::open(array('action' => "WelcomeController@log_in")) }}
    ...
    {{ Form::close() }}
    
    0 讨论(0)
  • 2020-12-29 21:41

    I wanted to store a post in my application, so I created a controller of posts (PostsController) with the resources included:

    php artisan make:controller PostsController --resource

    The controller was created with all the methods needed to do a CRUD app, then I added the following code to the web.php in the routes folder :

    Route::resource('posts', 'PostsController');

    I solved the form action problem by doing this:

    1. I checked my routing list by doing php artisan route:list
    2. I searched for the route name of the store method in the result table in the terminal and I found it under the name of posts.store
    3. I added this to the action attribute of my form: action="{{route('posts.store')}}" instead of action="??what to write here??"
    0 讨论(0)
  • 2020-12-29 21:42

    You can use the action() helper to generate an URL to your route:

    <form method="post" action="{{ action('WelcomeController@log_in') }}" accept-charset="UTF-8">
    

    Note that the Laravel 5 default installation already comes with views and controllers for the whole authentication process. Just go to /home on a fresh install and you should get redirected to a login page.

    Also make sure to read the Authentication section in the docs


    The error you're getting now (TokenMismatchException) is because Laravel has CSRF protection out of the box

    To make use of it (and make the error go away) add a hidden field to your form:

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

    Alternatively you can also disable CSRF protection by removing 'App\Http\Middleware\VerifyCsrfToken' from the $middleware array in app/Http/Kernel.php

    0 讨论(0)
  • 2020-12-29 21:45

    1) In Laravel 5 , form helper is removed .You need to first install laravel collective .

    Refer link: https://laravelcollective.com/docs/5.1/html

    {!! Form::open(array('route' => 'log_in')) !!}
    

    OR

    {!! Form::open(array('route' => '/')) !!}
    

    2) For laravel 4, form helper is already there

    {{ Form::open(array('url' => '/')) }}
    
    0 讨论(0)
  • 2020-12-29 21:53

    Form Post Action :

    <form method="post" action="{{url('login')}}" accept-charset="UTF-8">
    

    Change your Route : In Routes -> Web.php

    Route::post('login','WelcomeController@log_in');
    
    0 讨论(0)
提交回复
热议问题