Demac Media Demac Media Brand Demac Media Brand



Benefits of Using Default Magento Forms

Timer Icon 3 Mins

eCommerce, Magento Commerce

Creating new forms for your website seems easy enough – you take a design, add some HTML and CSS to make it look pretty, and add some validation to it. However, that approach may cause some headaches in the future, since you’re doing more work to create something that is less Magento friendly. Here are the reasons why using default Magento forms will save you time, and make your forms Magento friendly.

1. Validation

In default Magento forms, there are built-in validation tools available. For example, in an input box, the classes ‘required-entry’ and ‘validate-email’ are for validation purposes. This means that the email entry is required, and that the value must match the regex of an email address.

<input class=”required-entry validate-email” id=”email” type=”text” name=”email” value=”” />

Upon validation, it will add a ‘validation-passed’ or ‘validation-failed’ class to the field depending on if it passed or failed. In doing so, Magento has added a validation advice and an icon to notify the user of the validation result.

Here is an example of a failed validation:

Screen Shot 2014-02-25 at 4.57.25 PM

Passed validation:

Screen Shot 2014-02-25 at 4.57.47 PM

Different validation messages:

Screen Shot 2014-02-25 at 5.17.57 PM

Different validation messages, even more detailed:

Screen Shot 2014-02-25 at 5.18.20 PM

Useful Validation Classes

The following are some useful validation classes:

Having Magento validate your input will also save the user from having to submit and refresh the page if the user has an invalid input.

2. Reusing the same controller

Although it varies on what you want to achieve, it is generally good practice to reuse code whenever possible. Custom functions can be added after extending the default Magento controller. Since the default forms and controllers have matching names for input, there won’t be any need to modify the code except for only the inputs you have added. Also, it will be easier to see which of your inputs are custom and which are not, since the only ones in your controller will be the custom ones.

3. Styling

This goes hand-in-hand with reusing code, but is mentioned again as themed styling is such an important benefit from using default Magento forms. If you use default templates for creating custom forms, you will have the same class names for your HTML elements. This means that the styling you have done for this page can be carried onto other pages (if you want it to). This can save you from having to style every custom template you create.

So next time you need to create a custom form, see if you can copy it from default Magento and make your modifications from there!

Subscribe to the Blog

Stay updated with 20,000+ eCommerce leaders in our community

Sign Up

Let’s talk about your 10X return

Icon/Social/Phone Contact us for pricing information