Magento Admin Form – Add Value of ID Parameter to Field

adminforms

Using admin forms I would like to add a facility which will allow a user to upload an image and link it to some data held within other tables. My database is set up and my form is set up as required, unfortunately I have been unsuccessful in working out how to pass the id value from the url to the field on my form

How do I pass the id value from the url to the field on my form?

I have this

protected function _prepareForm()
{
    ....Other code here....

    $fieldset->addField('shop_id', 'hidden', array(
        'value'     => //unable to work out what command needs to be added,
        'name'      => 'shop_id',
    ));
}

Best Answer

Add this at the end of the form configuration

$form->addValues(array('shop_id'=>Mage::app()->getRequest()->getParam('shop_id')));

Or you can make the form submit to an url that has a get parameter named shop_id with the value of the shop id you need (I mean pass the get param shop_id to the page that handles the save action).