Magento 1.9 – Element with id ‘path’ already exists

magento-1.4magento-1.9

I was able to find this question that seems to be similar to my problem, however, my problem is different.

I'm migrating a site from Magento 1.4 to Magento 1.9. To perform this migration I've tried doing an incremental update with magerun. I've also tried to start with a fresh Magento 1.9 install and then transfer over the themes, plugins, and the database. With both situations I'm getting an error:

a:5:{i:0;s:37:"Element with id "path" already exists";i:1;s:5595:"#0 /web/virtual-servers/xxxxxxxxxxxxxxx.net/www_home/lib/Varien/Data/Form/Element/Abstract.php(58): Varien_Data_Form->checkElementId('path')

I tried removing all of the old plugins and I'm still getting the same error.

What does this error mean? There don't seem to be any duplicate categories or settings in the database.

Best Answer

The error means that an element (object) was being added to a form (object), but the form requires uniquely identified elements. In Magento, you typically create a new instance of a form, then a fieldset, and append fields to the fieldset. Here's an example of how it might look in code:

    $model = Mage::registry('cms_block');

    $form = new Varien_Data_Form(
        array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post')
    );

    $form->setHtmlIdPrefix('block_');

    $fieldset = $form->addFieldset('base_fieldset', array('legend'=>Mage::helper('cms')->__('General Information'), 'class' => 'fieldset-wide'));

    if ($model->getBlockId()) {
        $fieldset->addField('block_id', 'hidden', array(
            'name' => 'block_id',
        ));
    }
    ...

The above is taken from Mage_Adminhtml_Block_Cms_Block_Edit_Form::_prepareForm, and you will likely see the same methodology used for all core admin form setups.

The problem is that somewhere another form field with the ID of path is being added to a fieldset when one already exists.

So you can try to search your codebase for something like this:

grep -rn "addField('path" /app/code/[local|community]

And see if there are easy-to-spot duplicates. A quick scan myself over the core code pool yields:

./app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/General.php:63://            $fieldset->addField('path', 'select', array(
./app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/General.php:77:            $fieldset->addField('path', 'hidden', array(
./app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/General.php:86:            $fieldset->addField('path', 'hidden', array(
./app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Attributes.php:89:                    $fieldset->addField('path', 'hidden', array(
./app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Attributes.php:95:                    $fieldset->addField('path', 'hidden', array(
./app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Attributes.php:106:                $fieldset->addField('path', 'hidden', array(

And so it's possible that your issue lies with some third-party extension that tries to modify or extend a part of the category management forms.

As I said the fields will typically be registered as part of this _prepareForm method, but it's also possible that within one of these classes there is an event dispatched. For example, see the end of the Mage_Adminhtml_Block_Cms_Page_Edit_Tab_Content::_prepareForm method. This exposes the form to other modules (maybe a third-party extension) that might be causing your issue.

Related Topic