Without submit button validate form elements in Magento

Without submit button validate form elements in Magento

August 4, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Without submit button validate form elements in Magento

Multistep Form Validation in Magento: A Comprehensive Guide

Forms are one of the most critical components of any e-commerce platform. They allow customers to register accounts, make purchases, and interact with your store. In this post, we will explore how to create a multi-step form validation process in Magento, using an example of a user registration flow.

Understanding Multistep Form Validation

A multistep form breaks down the traditional single-page submission into smaller, manageable steps. This approach improves the user experience by reducing cognitive overload and making the process more navigable. It’s particularly useful for complex forms like user registrations or checkout processes.

Implementing a Two-Step Registration Form in Magento

Let’s break down the implementation of a two-step registration form with validation:

Step 1: Setting Up the Layout

First, you need to create your layout XML file (e.g., app/design/frontend/default/yourtheme/layout/magento-register.xml):

<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layouts.xsd">
    <layout id="customer_account_create">
        <referenceBlock name="form.additional.info.fieldset">
            <action method="setShowTitle" xsi:type="string">false</action>
        </referenceBlock>
    </layout>
</layout>

This layout file hides the additional information fieldset on the registration page.

Step 2: Creating Custom Templates

Next, create your custom templates for each step:

  • app/design/frontend/default/yourtheme/Magento_Customer/templates/form/register.phtml (Step 1)
  • app/design/frontend/default/yourtheme/Magento_Customer/templates/form/register_step2.phtml (Step 2)

In the register.phtml, include only the first step fields and a “Next” button:

<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="form-validate">
    <?php if ($this->helper('Magento\Customer\Helper\Session')->isLoggedIn()): ?>
        <div class="message message-success message-info">
            <strong><?php /* @escapeNotVerified */ echo __('You are already logged in.') ?></strong>
        </div>
    <?php else: ?>
        ...
        <!-- Step 1 fields go here -->
        <div class="actions-toolbar">
            <div class="primary">
                <button type="submit" name="send" id="send" value="<?php /* @escapeNotVerified */ echo __('Next') ?>" class="action submit primary action-default-primary">
                    <span><?php /* @escapeNotVerified */ echo __('Next') ?></span>
                </button>
            </div>
        </div>
    <?php endif; ?>
</form>

Step 3: Implementing JavaScript Validation

Use jQuery to handle the form submission logic and validate the fields:

require(['jquery'], function ($) {
    $('#send').click(function (e) {
        e.preventDefault();
        var isValid = true;

        if (!validateField('firstname')) {
            isValid = false;
        }
        // Add more validation conditions here

        if (isValid) {
            $('div.shipping-address-fields').show(); // Show Step 2
            $('#step1').hide(); // Hide Step 1
        } else {
            alert('Please fill out all required fields.');
        }
    });
});

Step 4: Updating the Form Action

Finally, update your form action to redirect the user to a custom controller for handling each step’s submission. Create a new PHP file app/code/Vendor/Module/Controller/Register.php and handle the form submissions according to each step.

Conclusion

Creating multistep forms in Magento involves a combination of layout updates, template modifications, JavaScript validation, and backend processing. By following this approach, you can enhance your customers’ user experience by making complex processes more manageable and intuitive.

Remember to thoroughly test your implementation across different browsers and devices to ensure compatibility. If you’re looking for expert guidance on Magento development and best practices, feel free to explore our services at Laravel Company.

Happy coding!

Checkout Themes Configuration Customers

Our network