Monday, 15 September 2014

php - How to set default value for form fields- Magento? -



php - How to set default value for form fields- Magento? -

i have admin form field(textbox),

$fieldset->addfield('ajax_time_interval', 'text', array( 'label' => mage::helper('dealroom')->__('page refresh time interval'), 'class' => 'required-entry', 'required' => true, 'name' => 'ajax_time_interval', ));

i need set default value text field. tried, setting 'value' => '120', in it. not working.

$fieldset->addfield('ajax_time_interval', 'text', array( 'label' => mage::helper('dealroom')->__('page refresh time interval'), 'class' => 'required-entry', 'required' => true, 'name' => 'ajax_time_interval', 'value' => '120', ));

how set defalt value in field?

in case, setvalues() function overriding 'value' had set field.

cause:

in _prepareform() function, set value below:

$fieldset->addfield('ajax_time_interval', 'text', array( 'label' => mage::helper('dealroom')->__('page refresh time interval'), 'class' => 'required-entry', 'required' => true, 'name' => 'ajax_time_interval', 'value' => '120', ));

at end of _prepareform() function, there next line of code reset form values:

$form->setvalues($model->getdata());

solution:

set model info before setvalues() function below:

if (!$model->getid()) { $model->setdata('ajax_time_interval', '120'); } $form->setvalues($model->getdata());

php magento

No comments:

Post a Comment