Send boolean data in postman form-data

Send boolean data in postman form-data

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

Stefan Bogdanescu

Founder & Senior Architect

Send boolean data in Postman form-data

When building APIs, handling user input correctly is fundamental to logic flow. A common friction point occurs when sending boolean-like values via HTTP requests. If you attempt to send a true or false value using Postman's "form-data" collection and receive unexpected behavior in your PHP backend—specifically if every value evaluates as truthy—you are likely encountering how the HTTP protocol encodes data, not a bug in your casting logic.

The core issue stems from how standard HTML forms (and by extension, multipart/form-data) transmit values. These fields are text-based. When you select "true" or "false" in Postman's dropdown for a form field, the tool does not automatically serialize this into a JSON boolean or an empty string. Instead, it typically sends the literal string "true" or "false" as the value.

In PHP, strings are truthy by default. The expression if ("true") evaluates to true. Consequently, even if you apply manual casting like (bool)$request->isDiscount, a non-empty string will cast to true. The same applies to boolVal(); unless the input is an empty string or null, it returns true. This explains why your conditional checks for if ($request->isDiscount) always execute regardless of whether you selected "true" or "false" in the client.

To resolve this, you must explicitly define how the boolean value is transmitted over the wire. There are two primary approaches depending on your backend constraints and frontend capabilities.

Option 1: Explicit String Values with a Helper Method

If you must stick to multipart/form-data (e.g., submitting from a legacy form builder or specific mobile SDKs), you need to ensure the client sends distinct string markers that your server can distinguish from an empty value.

In Postman, change the "Key" value to whatever your backend expects for false, often "0" or an empty string "", and use "1" or a specific flag like "active" for true. However, if you are strictly relying on the text "true" and "false", your PHP code must treat these as strings until validation occurs.

You can create a helper method in your Laravel controller or model to normalize this input:

public function handleDiscount(Request $request) {
    // Normalize the incoming string 'true'/'false'/'0'/'1'/'yes'/'no' into a boolean
    $isDiscount = $request->boolean('isDiscount'); 
}

The boolean() accessor in Laravel is powerful here. It attempts to convert the input to a boolean using standard PHP logic. However, it treats empty strings as false and non-empty strings (including "true", "false", "1", "0") as true unless you handle the specific string values manually. A more robust pattern for this specific scenario involves checking against known "false" strings:

$isDiscount = in_array($request->isDiscount, ['', 'no', 'false', '0'], true) ? false : true;

This approach ensures that if a user sends an empty string (common when toggles are off), the logic correctly identifies it as false.

Option 2: Switching to application/json

The most robust solution for modern APIs is to abandon form-data for boolean fields and switch to application/json. JSON has native support for booleans, where true and false are distinct types, not strings.

In Postman, set the request body type to "raw" and select "JSON". Manually type:

{
  "price": 100,
  "isDiscount": true
}

When your Laravel application receives this, $request->boolean('isDiscount') will work as expected because the input is genuinely a boolean type in the JSON payload.

Trade-offs and Pitfalls

The trade-off here is between convenience and strictness. multipart/form-data is flexible but ambiguous; it relies on string conventions that vary by framework and client. If you accept "false" as a string, you risk accepting "FALSE", "False", or "false " (with whitespace) as valid inputs if you aren't trimming or normalizing strictly.

Using application/json eliminates this ambiguity entirely but requires the client to support JSON payloads. For many modern web and mobile applications, switching to JSON is the recommended path to avoid the "string always equals true" trap described in your scenario. Always prefer typed data (JSON) over untyped data (form-data) for logical flags like booleans.

Our network