1

I am trying to add a time field to an admin form but it does not work:

    $fieldset->addField('sched_time', 'time', array(
      'label'     => Mage::helper('servicemanager')->__('Scheduled Time'),
      'style'     => 'width:45px',
      'class'     => 'required-entry',
      'required'  => true,
      'name'      => 'sched_time',
      'value'  => '09,00,00',
    ));

The problems are as follows:

  1. The data isn't getting stored in the database ('sched_time' is a mysql time field)
  2. 'value' doesn't do anything. I need the default value to be set to 09:00:00 (9am)

Reference: http://www.excellencemagentoblog.com/magento-admin-form-field

Nicholas.V
  • 1,926
  • 2
  • 15
  • 30

2 Answers2

1

You need to write some code manually in your controller's saveAction() method which might look like:

public function saveAction(){
    $id = $this->getRequest()->getParam('id');
    $model = Mage::getModel('module/model')->load($id);
    $time = $this->getRequest()->getParam('sched_time');
    $sched_time = $time[0] . ':' . $time[1] . ':' . $time[2]; //HH:MM:SS
    $model->setData('sched_time', $sched_time);
    $model->save();
}

Hope this will help future visitors!

Mohammad Faisal
  • 5,783
  • 15
  • 70
  • 117
0

You need to make an observer, after hours trying to find this myself I came across this link magento weight attribute without decimal points

Hope this helps as it helped me

Community
  • 1
  • 1
MrsPop88
  • 303
  • 4
  • 14