Checking if a POST form has been submitted using PHP

Checking if a POST form has been submitted using PHP

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

The Hidden Field Pattern vs. Request Attributes

Determining whether a form has been submitted is a fundamental requirement for separating your display logic from your processing logic. When a user visits a page, you want to render the empty form. When they click submit, you want to validate input and potentially save data. If you rely solely on isset($_POST), you are technically correct but practically wrong, as that superglobal exists regardless of whether any request method is in use or if the array is empty. Iterating through specific fields with a long chain of || isset() checks is brittle and violates the DRY principle; adding new form fields breaks your validation gate without updating the conditional logic.

The most pragmatic solution for vanilla PHP is indeed the hidden flag field. While it feels like introducing state into the request, it is semantically accurate: the user has explicitly initiated a submission event by triggering the POST action on the form tag. You can define an attribute named submitted or form_action with a value of 1. On your processing endpoint, you check if this specific key exists in $_POST. If it does, the request is treated as a submission; if not, the form renders cleanly.

if (isset($_POST['submitted'])) {
    // Process validation and logic
} else {
    // Render the form view
}

However, this approach relies on the assumption that the form tag itself contains the hidden field. If you are using a framework or a templating engine that generates HTML dynamically, manually inserting this flag can become error-prone if not handled consistently across all views. This is where modern PHP frameworks abstract away the raw superglobals to provide a cleaner interface for request inspection.

In the Laravel ecosystem, specifically version 5.1 and later, the framework provides a dedicated method on the Request object to solve this exact problem: isMethod(). You can pass the string 'POST' to this method, and it returns true if the incoming HTTP request uses the POST method, regardless of whether the $_POST array is empty or populated. This removes the need for custom hidden fields entirely, as the decision is based on the HTTP protocol itself rather than a specific key within the payload.

$request = Request::capture();

if ($request->isMethod('post')) {
    // Handle form submission
} else {
    // Render form
}

Using isMethod() aligns with RESTful principles where the HTTP verb dictates the action being performed. It is also safer against CSRF attacks when combined with proper middleware, as you are gating logic based on the transport layer rather than trusting a specific string inside the body. That said, if you are building a legacy application without a framework, or if your form submission mechanism involves asynchronous JavaScript that bypasses standard form tags (such as AJAX calls that might not trigger the full page reload expected by isMethod in certain routing configurations), the hidden field remains a valid fallback for vanilla PHP.

Ultimately, the choice depends on your environment. If you are writing raw PHP, the hidden flag is the standard convention because it explicitly signals intent within the payload. If you have access to a framework like Laravel, leveraging built-in utilities like isMethod() offers a cleaner separation of concerns and reduces the cognitive load of managing custom request attributes.

For teams adopting modern workflows or looking to streamline their codebase, checking frameworks that offer robust request handling can eliminate these manual checks entirely. Resources discussing modern PHP practices and framework integration can be found at https://laravelcompany.com.

Our network