skip to Main Content

I’m facing a persistent 419 error in my Laravel application, which not only affects form submissions but also occurs on the login page. Despite implementing several solutions, the problem persists, and I’m reaching out for help and fresh perspectives.

Here are the steps I’ve taken to address the issue:

  1. Ensured @csrf is Present: I’ve confirmed that the @csrf directive is present in my forms.
  2. Tried {{ csrf_field() }}: I’ve also attempted to use {{ csrf_field() }} as an alternative.
  3. Adjusted Session Domain: I’ve set the session domain to match the website’s URL.
  4. Increased Maximum Upload Time: I’ve increased the maximum upload time.
  5. Reset CageFS: I even went as far as resetting CageFS.
  6. Replaced TinyMCE with Summernote: Initially, I suspected TinyMCE, so I replaced it with Summernote, but the problem persists.
  7. Investigated the ‘longtext’ Field: I initially thought the issue might be related to the ‘longtext’ field, but it submitted once and then failed on the very next attempt.
    8.included

What’s particularly perplexing is that this 419 error is not limited to form submissions but also occurs on the login page. This leads me to believe that there might be a deeper issue with CSRF token verification or session management.

I would greatly appreciate any insights, suggestions, or solutions from the experienced developers here. If you need specific code snippets, configuration details, or additional information to assist in diagnosing the problem, please feel free to ask, and I’ll provide them promptly.

Thank you immensely for your assistance and expertise.

Edit:

The issue with the 419 error on the login page has been successfully resolved by correcting a session_domain misplacement.

However, I’m still encountering a problem when using the "AddProduct" feature, especially with long text inputs. To restructure the issue:

The "AddProduct" functionality is working well when short text inputs are used, but when I attempt to submit longer text inputs, the application encounters issues. Specifically, when I provide lengthy text in certain fields, the submission fails, resulting in the 419 error.

login page:

  <form method="POST" action="{{ route('login') }}">
                        @csrf

                        <div class="mb-3">
                            <label for="login" class="form-label">{{__('Email/Phone/Name')}}</label>
                            <input class="form-control @error('login') is-invalid @enderror" id="login" type="text" name="login" :value="old('login')" required autofocus>
                        @error('login')
                            <span class="text-danger"> {{$message}}</span>
                            @enderror
                        </div>


                        <!-- Password -->
                        <div class="mb-3">
                            <label for="password" class="form-label">{{__('Password')}}</label>
                            <div class="input-group input-group-merge">
                                <input type="password" id="password" class="form-control @error('password') is-invalid @enderror" name="password"
                                       required autocomplete="current-password"/>
                                <div class="input-group-text" data-password="false">
                                    <span class="password-eye"></span>
                                </div>
                            </div>
                            @error('login')
                            <span class="text-danger"> {{$message}}</span>
                            @enderror
                        </div>

                        <!-- Remember Me -->
                        <div class="mb-3">
                            <div class="form-check">
                                <input type="checkbox" class="form-check-input" id="checkbox-signin" checked name="remember">
                                <label class="form-check-label" for="checkbox-signin">Remember me</label>
                            </div>
                        </div>


                        <div class="text-center d-grid">
                            @if (Route::has('password.request'))
                                <a class="underline text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:focus:ring-offset-gray-800" href="{{ route('password.request') }}">
                                    {{ __('Forgot your password?') }}
                                </a>
                            @endif
                            <button class="btn btn-primary" type="submit">  {{ __('Log in') }} </button>
                        </div>

                    </form>

AddProduct blade:

<form id="myForm" method="POST" action="{{route('product.store')}}" enctype="multipart/form-data">
                
                {{ csrf_field() }}
                
                <h5 class="mb-4 text-uppercase"><i class="mdi mdi-account-circle me-1"></i> Product Info</h5>
                <div class="row">
                    <div class="col-md-6">
                        <div class="form-group mb-3">
                            <label for="name" class="form-label">Product Name</label>
                            <input type="text" name="product_name" class="form-control @error('product_name') is-invalid @enderror" id="name" >

                            @error('product_name')
                            <span class="text-danger"> {{$message}}</span>
                            @enderror
                        </div>
                        </div>

                    <div class="col-md-6">
                        <div class="form-group mb-3">
                            <label for="category" class="form-label">Category </label>
                            <select name="category_id" class="form-select form-group @error('category_id') is-invalid @enderror" id="example-select">
                                <option disabled selected >Select Category</option>
                                @foreach($categories as $category)
                                    <option  value="{{$category->id}}">{{$category->category_name}}</option>
                                @endforeach
                            </select>
                            @error('category_id')
                            <span class="text-danger"> {{$message}}</span>
                            @enderror
                        </div>
                    </div> <!-- end col -->

                    <div class="col-md-6">
                        <div class="form-group mb-3">
                            <label for="supplier" class="form-label">Supplier </label>
                            <select name="supplier_id" class="form-select @error('supplier_id') is-invalid @enderror" id="example-select">
                                <option disabled selected>Select Supplier</option>
                                @foreach($suppliers as $supplier)
                                    <option  value="{{$supplier->id}}">{{$supplier->name}}</option>
                                @endforeach
                            </select>
                            @error('supplier')
                            <span class="text-danger"> {{$message}}</span>
                            @enderror
                        </div>
                    </div> <!-- end col -->
              

                    <div class="col-md-6">
                        <div class="form-group mb-3">
                            <label for="phone" class="form-label">Buying Price</label>
                            <input type="text" name="buying_price" class="form-control @error('buying_price') is-invalid @enderror" id="buying_price">

                            @error('buying_price')
                            <span class="text-danger"> {{$message}}</span>
                            @enderror
                        </div>
                    </div> <!-- end col -->
                    <div class="col-md-6">
                        <div class="form-group mb-3">
                            <label for="phone" class="form-label">Selling Price</label>
                            <input type="text" name="selling_price" class="form-control @error('selling_price') is-invalid @enderror" id="selling_price">

                            @error('selling_price')
                            <span class="text-danger"> {{$message}}</span>
                            @enderror
                        </div>
                    </div> <!-- end col -->

                    <div class="col-md-6">
                        <div class="form-group mb-3">
                            <label for="phone" class="form-label">Product Quantity</label>
                            <input type="number" name="product_store" class="form-control @error('product_store') is-invalid @enderror" id="product_store">

                            @error('product_store')
                            <span class="text-danger"> {{$message}}</span>
                            @enderror
                        </div>
                    </div> <!-- end col -->

                    <div class="col-md-6">
                        <div class="form-group mb-3">
                            <label for="phone" class="form-label">Selling Price</label>--}}
                            <input type="text" name="selling_price" class="form-control @error('selling_price') is-invalid @enderror" id="selling_price">

                            @error('selling_price')--}}
                            <span class="text-danger"> {{$message}}</span>
                           @enderror
                        </div>--}}
                 </div> <!-- end col -->

                     <div class="col-md-12">
                        <div class="form-group mb-3">
                            <label for="phone" class="form-label">Product Description</label>
                            <textarea type="text" name="product_description" class="form-control @error('product_description') is-invalid @enderror" id="mysummernote"></textarea>

                            @error('product_description')
                            <span class="text-danger"> {{$message}}</span>
                            @enderror
                        </div>
                    </div> <!-- end col -->


                     <div class="col-md-12">
                        <div class="form-group mb-3">
                            <label for="phone" class="form-label">Product Features</label>
                            <textarea type="text" name="product_features" class="form-control @error('product_features') is-invalid @enderror" id="my2summernote"></textarea>

                            @error('product_features')
                            <span class="text-danger"> {{$message}}</span>
                            @enderror
                        </div>
                    </div> <!-- end col -->
                    <div class="col-md-12">
                        <div class="form-group mb-3">
                            <label for="example-fileinput" class="form-label">Product Image</label>
                            <input type="file" name="product_image" class="form-control" id="image">

                        </div>

                        <img id="showImage" src="{{(!empty($product->product_image))? url('upload/product/'.$product->product_image) : url('upload/no_image.jpg')}}" class="rounded-circle avatar-lg img-thumbnail"
                             alt="profile-image">
                    </div> <!-- end col -->
                </div> <!-- end row -->


                <div class="text-end">
                    <button type="submit" class="btn btn-success waves-effect waves-light mt-2"><i class="mdi mdi-content-save"></i> Save</button>
                </div>
            </form>

2

Answers


    • Check Request Size: Ensure that your server configuration allows for larger requests, adjusting post_max_size and upload_max_filesize in PHP settings and maxPostSize in Laravel configuration if needed.

    • Validation Rules: Review and update your Laravel validation rules to accommodate larger text inputs, adjusting max rules if necessary.

    • Error Logs: Check server and Laravel logs for more detailed error messages that might pinpoint the issue.

    • Middleware: Confirm that CSRF protection is applied to the "AddProduct" route and hasn’t been excluded inadvertently.

    • Database Constraints: Verify that your database columns can store longer text inputs if you’re storing form data in a database.

    Login or Signup to reply.
  1. 419 is TokenMismatchException .put you route at :routes/web.php

      protected function prepareException(Exception $e)
        {
            if ($e instanceof ModelNotFoundException) {
                $e = new NotFoundHttpException($e->getMessage(), $e);
            } elseif ($e instanceof AuthorizationException) {
                $e = new AccessDeniedHttpException($e->getMessage(), $e);
            } elseif ($e instanceof TokenMismatchException) {
                $e = new HttpException(419, $e->getMessage(), $e);
            } elseif ($e instanceof SuspiciousOperationException) {
                $e = new NotFoundHttpException('Bad hostname provided.', $e);
            }
    
            return $e;
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search