Home > database >  Error 403: I got 403 error when i submit the form in laravel
Error 403: I got 403 error when i submit the form in laravel

Time:12-20

when i submit the form server give me a 403 error. when i insert special characters in textarea.

Blade file:

<form action="submit_error" method="POST">
   @csrf
   <div >
       <label for="">Title</label>
       <input type="text"  id="" name="title" placeholder="Write your question">
   </div>
   <div >
       <label for="">Description</label>
       <textarea  id="" rows="3" name="description" placeholder="Write Your problem in detail"></textarea>
   </div>
   <script src="https://cdn.ckeditor.com/4.19.1/full/ckeditor.js"></script>
   <label for="exampleFormControlTextarea1" >What did you try?</label>
   <textarea name="err_code" placeholder="Write your code"></textarea>
   <script>
       CKEDITOR.replace( 'description' );
   </script>
   <script>
       CKEDITOR.replace( 'err_code' );
   </script>
   <div >
        <label for="">Tag</label>
        <input type="text"  id="" name="tag" placeholder="Add one tag about your query ex:Php">
   </div>
   <button type="submit" >Post Error</button>

Controller Code:

public function submit_error(Request $request)
    {
        $all_data =  $request->all();
        $user_id = Auth::id();
        $user_name = User::where('id',$user_id)->value('name');
        $slug = str_slug($all_data['title']);
        
        $tag_find = DB::table('tags')->where('tags',$all_data['tag'])->exists();
        
        if($tag_find != '1'){
            $tag_find = DB::table('tags')->insert([
                'tags' => $all_data['tag']
                ]);
        }

         
        $askerror = AskError::create([
            'user_name' => $user_name,
            'title' => $all_data['title'],
            'description' => $all_data['description'],
            'err_code' => $all_data['err_code'],
            'tag' => $all_data['tag'],
            'slug' => $slug
        ]);
        

        return redirect()->route('index');
    }

when i insert special characters in textarea then i got a 403 error. so, how to solve it?

CodePudding user response:

Your form action attribute is not correct. Change from

<form action="submit_error" method="POST">

to

<form action="{{ route('submit_error') }}" method="POST">

Also make sure you have added the route name on routes/web.php file like this sample.

Route::post('submit_error', 'YourController@submit_error')->name('submit_error');

CodePudding user response:

The issue must be in your action part of the form. Check if the route exists or even better, use route().

  • Related