Magento Force State/Province Value even if blank

Magento Force State/Province Value even if blank

August 30, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento Force State/Province Value even if blank

Solving State/Province Field Issues in Magento for International Orders

As an experienced e-commerce developer, I often encounter situations where clients are using third-party payment gateways that have specific field requirements, even for international orders without state or province designations. In this case, you’re facing a challenge with Sage Payment Solutions requiring a state field value for validation purposes.

Understanding the Problem: The State Field Requirement

The core issue here lies in Magento’s default behavior and the structure of your checkout form. When processing an order through Sage, the system expects a non-empty value for the ‘state’ field during validation. However, for countries without provinces or states (like Japan or Switzerland), this requirement conflicts with the actual data.

The Initial Attempt: Modifying the HTML Form

Your first approach involved adding a static default value (“XX”) to the state field in the billing template:

<option value="XX" selected="selected">-- please choose --</option>

This method should have worked, as it directly modifies the HTML structure used by Magento. However, you noticed that the change didn’t take effect.

Investigating Further: The JavaScript Layer

When dealing with form fields in Magento, it’s important to understand the interplay between the HTML and JavaScript layers. Magento uses JavaScript to update and validate certain fields during checkout, which can override static HTML defaults if not handled correctly.

A More Effective Approach: Overriding the JavaScript Function

To solve this issue systematically, let’s focus on the JavaScript function that handles the state field selection:

  1. Identify the relevant script: Look for a script file in your Magento installation that manages the onepage checkout process. It might be located under skin/js/opcheckout.js.

  2. Locate the state field handling code: Within this script, look for functions related to the state/province field, such as those called when a country is selected.

  3. Add a custom logic block: Insert a new block of JavaScript code within the relevant function that checks if the selected country does not have states or provinces (e.g., by comparing it with an array of countries without state divisions).

  4. Set a default value: If the condition is met, set a default value for the state field manually using the setValue method provided by Prototype.js:

if (selectedCountry === 'Japan' || selectedCountry === 'Switzerland') {
    Element.setValue('billing:region_id', 'XX');
}

This custom logic ensures that when you select a country without states, the state field is automatically populated with your desired default value (“XX”).

Ensuring Proper Override and Cache Management

To apply this fix effectively:

  • Make sure to place your override in an extension rather than directly modifying core files. This will prevent conflicts during updates and allow for easier maintenance.

  • Clear the Magento cache after making changes, as JavaScript files are cached by default in production mode.

Conclusion: Resolving State/Province Requirements with Precision

In summary, solving this challenge required a careful examination of both the HTML form structure and the underlying JavaScript functions that manage field validation. By strategically placing a custom logic block within the appropriate function, you can ensure that countries without state divisions are automatically populated with a suitable default value.

Remember to always work within an extension when making core modifications for easier maintenance and to prevent conflicts during updates. If you need assistance implementing this fix or have other Magento development needs, feel free to reach out to our team at Laravel Company.

With the provided solution, your international orders should now bypass the state field validation requirement of Sage Payment Solutions without compromising the integrity of your checkout process.

Checkout Themes Orders Import/Export

Our network