How To

How to Validate Form Without Submitting Data in Magento 2

Hello Magento Folks?,

How’s everything going on? I consider all of you to be safe and productive at home. To make this even more useful, today I have come up with the topic that How can We Validate form without Submitting Data in Magento 2. If you have missed our latest blog on Magento 2: How to add New Button to The Product List Page in Backend using UI Component , Then check it. So let’s get started?.

Introduction:

Nowadays, everyone is finding a reliable source to give their information. So today we’ll look upon the validation of the form without submitting the data in it.We can use the given code that will help you to assess your form before putting the information in it.So, here is the way how you can do that.Here is the code in your phtml file that will help you to validate form without submitting your data.

Here’s the code:

<script type="text/javascript">

    require(['jquery', 'jquery/ui','jquery/validate'], function($){

        jQuery(document).ready( function() {

            var data = jQuery('#your_id');

            var check_null_val = null;




            data.mage('validation', {

                check_null_val: check_null_val ? ':hidden:not(' + check_null_val + ')' : ':hidden'

            }).find('input:text').attr('autocomplete', 'off');




            jQuery('#your_id').on('blur', function() {

                data.validation('isValid'); //returns boolean

            });

        });

    });

</script>

Final Words

Assuming that you are now equipped with the validation of the form without submitting. With the help of these codes, you can successfully assure the reliability of the form and safely put your information in it. You are free to play around and use these codes as per your necessity for fetching data. If you face any problems while implementing, then contact our support team. We will be happy to help you.

Happy coding!

Click to rate this post!
[Total: 9 Average: 4.2]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate ?️ Certified Magento Developer?‍?. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.?

View Comments

Recent Posts

Magento 2: How to Save Custom Field Value to quote_address for Multi-Shipping Orders

Hello Magento Friends, In Magento 2, the checkout process allows customers to choose multiple shipping…

7 hours ago

Best Beginners Guide to Shopify Balance Account

If you are a Shopify admin, using a Shopify Balance Account for your business revenue…

7 hours ago

8 Best Social Login Apps for Shopify Store in 2024

Running an eCommerce business can be incredibly demanding, leaving entrepreneurs little time to focus on…

7 hours ago

Generating Thumbnails with Spatie Media Library in Laravel 11: A Step-by-Step Guide

Generating image thumbnails is a common requirement in web applications, especially when handling media-heavy content.…

1 day ago

Enhancing Web Application Security with Laravel’s Built-In Features

In today’s digital landscape, web application security is paramount. As a powerful PHP framework, Laravel…

2 days ago

Magento 2 Extensions Digest October 2024 (New Release & Updates)

October was an exciting month for MageComp! From significant updates across our Magento 2 extension…

2 days ago