How to check if form submitted in laravel?

Member

by lottie , in category: PHP Frameworks , a year ago

How to check if form submitted in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by ryleigh , a year ago

@lottie 

In Laravel, you can check if a form has been submitted by checking if the request method is POST and if the form token matches the CSRF token.


You can do this by using the following code in your controller or route handler:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
use IlluminateHttpRequest;

public function submitForm(Request $request)
{
    if ($request->isMethod('post') && $request->has('_token')) {
        // Form has been submitted
        // Your code here
    } else {
        // Form has not been submitted
    }
}


This code checks if the request method is POST and if the CSRF token is present in the form data. If both conditions are met, it means that the form has been submitted. You can then perform any necessary actions with the form data inside the if statement block.

Related Threads:

How to get submitted data in the same form in laravel?
How to validate a laravel form using jquery ajax?
How to check if database row exist in laravel?
How to use form builder in laravel?
How to store large form in laravel?
How to fix laravel form submit?