2

I have module created with UMC ( ultimate module creator ) named consultancy. I have successfully added a field on Add/edit page with following code which I found in form.php file.

$fieldset->addField(
            'price_usd',
            'text',
            array(
                'label' => Mage::helper('abhi_consulting')->__('Price USD'),
                'name'  => 'price_usd',
            'required'  => true,
            'class' => 'required-entry',

           )
        );

other fields were added same way so i just copy pasted and changed the key, now the field is available but the value is not saving and showing blank.

I looked into the code but didnt find any save function. How do I save value for new added field ?

1 Answer 1

2

To save value you need to have filed in database too.

When you say

so i just copy pasted and changed the key, now the field is available but the value is not saving and showing blank

I believe you didn't create a column for this in your database.

You need to add an update sql then it will save as required.

Create a file- sql/your_setup_name/upgrade-[your-current-version]-[any-version].php

<?php
$installer = $this;
$connection = $installer->getConnection();
$installer->startSetup();

$installer->getConnection()
    ->addColumn($installer->getTable('abhi_consulting/yourmodel'),
        'price_usd',
        array(
            'type'      => Varien_Db_Ddl_Table::TYPE_DECIMAL,
            'precision' => 12,
            'scale'     => 4,
            'nullable'  => true,
            'default'   => null,
            'comment'   => 'Your comment'
        )
    );

$installer->endSetup();

You need to change yourmodel to your own model, not sure how you have setup your config.xml.

Now,

Simply go to your etc/config.xml and update your version. Basically it should match with [any-version] exactly.

Hope this is clear for you.

4
  • thanks @Adarsh , I did what you suggest but now getting following error as I am new to magento, not sure how to resolve this. Call to undefined method Magento_Db_Adapter_Pdo_Mysql::run()
    – Vikram
    Commented May 16, 2016 at 4:20
  • Can you add your config.xml and also folder structure screenshot please. Commented May 16, 2016 at 4:34
  • I ended up by adding the field directly through phpmyadmin, will look into it after finishing the task.
    – Vikram
    Commented May 16, 2016 at 4:56
  • I see, I would suggest to look in to upgrade part from this link inchoo.net/magento/… Commented May 16, 2016 at 4:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.