0

i cant set any default value for textfield or button in my custom admin grid form ,here is my code, iam following http://markshust.com/2012/07/05/creating-magento-adminhtml-grids-simplified tutorial protected function _prepareForm() {
$model = Mage::registry('custom_backorder');

    $form = new Varien_Data_Form(array(
        'id'        => 'edit_form',
        'action'    => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
        'method'    => 'post'
    ));

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

    if ($model->getId()) {
        $fieldset->addField('id', 'hidden', array(
            'name' => 'id',
        ));
    }  



    $fieldset->addField('User_Id', 'text', array(
        'name'      => 'User_Id',
        'disabled'  => TRUE,

        'label'     => Mage::helper('checkout')->__('UserId'),
        'title'     => Mage::helper('checkout')->__('UserId'),
        'required'  => true,
    ));
    $fieldset->addField('User_Email', 'text', array(
        'name'      => 'User_Email',
        'disabled'  => TRUE,
        'label'     => Mage::helper('checkout')->__('UserEmail'),
        'title'     => Mage::helper('checkout')->__('UserEmail'),
        'required'  => true,
    ));
    $fieldset->addField('Product_Id', 'text', array(
        'name'      => 'Product_Id',
        'disabled'  => TRUE,
        'label'     => Mage::helper('checkout')->__('ProductId'),
        'title'     => Mage::helper('checkout')->__('ProductId'),
        'required'  => true,
    ));
    $fieldset->addField('Product_Name', 'text', array(
        'name'      => 'Product_Name',
        'disabled'  => TRUE,
        'label'     => Mage::helper('checkout')->__('ProductName'),
        'title'     => Mage::helper('checkout')->__('ProductName'),
        'required'  => true,
    ));
    $fieldset->addField('Qty', 'text', array(
        'name'      => 'Qty',
        'label'     => Mage::helper('checkout')->__('Quantity'),
        'title'     => Mage::helper('checkout')->__('Quantity'),
        'required'  => true,
    ));
    $fieldset->addField('Avail_Qty', 'text', array(
        'name'      => 'Avail_Qty',
        'disabled'  => TRUE,
        'label'     => Mage::helper('checkout')->__('AvailableQuantity'),
        'title'     => Mage::helper('checkout')->__('AvailableQuantity'),
        'required'  => true,
    ));

    $fieldset->addField('Flag', 'text', array(
            'name'      => 'Flag',

            'label'     => Mage::helper('checkout')->__('Status'),
            'title'     => Mage::helper('checkout')->__('Status'),
            'required'  => true,
    ));

    $fieldset->addField('submit', 'submit', array(



        'value'     => 'Submit',
        'label'     => Mage::helper('checkout')->__('Submit'),
        'required'  => true
        /*'tabindex'  => 15*/
    ));
    $fieldset->addField('title', 'text', array(
      'label'     => Mage::helper('checkout')->__('Title3'),
      'class'     => 'required-entry',
      'required'  => true,
      'name'      => 'title',
      'onclick' => "alert('on click');",
      'onchange' => "alert('on change');",
      'style'   => "border:10px",
      'value'  => 'hello !!',
      'disabled' => false,
      'readonly' => true,
      'after_element_html' => '<small>Comments</small>',
      'tabindex' => 1
    ));

    ?>

    <?php
        $form->setValues($model->getData());
        //$form->setUseContainer(true);
        $this->setForm($form);
        return parent::_prepareForm();
}
2

Normally in this case what I do is save the model as using registry in the controller and thten read it in the prepare form function.

if (Mage::registry('model_data')) {
    $form->setValues(
        Mage::registry('model_data')
            ->getData()
    );
}

Then in your controller you can use the following snippet to save the model data.

Mage::register('model_data', $model);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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