Magento: Using a product chooser widget when creating a custom form in the admin panel

Magento: Using a product chooser widget when creating a custom form in the admin panel

August 27, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: Using a product chooser widget when creating a custom form in the admin panel

Displaying a Product Chooser Widget in Magento Admin Form

As an experienced Magento developer, I understand your need to streamline the admin experience by replacing manual text field entries with user-friendly widgets like product choosers. In this post, we’ll explore how to integrate a product chooser widget into your custom form within the admin panel.

Understanding the Current Setup

You’re currently using the addField method to create a simple text field for entering a product ID in your settings form. The code looks like this:

$fieldset->addField(
    'product_id',
    'text',
    array(
        'label'     => $helper->__('Product'),
        'class'     => 'required-entry',
        'required'  => true,
        'name'      => 'product_id'
    )
);

While this method works, it lacks the interactivity and validation that a dedicated product chooser widget provides.

Introducing the Catalog Product Widget

Magento offers a built-in catalog_product_widget block that handles displaying a product selector. To use this in your form, you’ll need to create an instance of this block and add its output to your fieldset.

First, make sure the catalog_product_widget block is available by enabling it in your module’s config.xml:

<global>
    <blocks>
        <your_module_name>
            <class>Mage_Catalog_Block_Widget</class>
        </your_module_name>
    </blocks>
</global>

Then, in your form file where you create the fieldset, include the following code:

$fieldset->addField(
    'product_id',
    'catalog_product_widget',
    array(
        'label'     => $helper->__('Product'),
        'class'     => 'required-entry',
        'required'  => true,
        'name'      => 'product_id'
    )
);

This code replaces the text field type with catalog_product_widget. The widget will now appear in your form, allowing administrators to select a product using an interactive interface.

Ensuring Proper Functionality

To ensure that the selected product ID is correctly saved and processed by your module:

  1. Make sure the ‘product_id’ name matches the field used for saving and processing.
  2. Validate the input on the server side to handle any potential errors or invalid selections.
  3. Update your form’s submission logic to handle the selected product ID appropriately.

For more detailed information on customizing Magento admin forms, I recommend checking out the official documentation: Creating Custom Admin Forms

Conclusion

By following the steps outlined above, you can easily replace a simple text field in your Magento admin form with a more user-friendly product chooser widget. This change improves the administrative experience and reduces the likelihood of errors when selecting products.

Remember to always test your changes thoroughly after implementation to ensure they function as expected within your custom module.

Happy coding! If you need further assistance or have other questions about Magento development, feel free to explore our comprehensive guides at Laravel Company.

Catalog Extensions Admin Configuration

Our network