1

I have a custom admin edit form with the following fields:

$dateTimeFormatIso = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
$fieldsetRefInfo->addField('start_date', 'date', array(
    'name' => 'start_date',
    'input_format' => Varien_Date::DATETIME_INTERNAL_FORMAT,
    'format' => $dateTimeFormatIso,
    'time' => true,
    'image' => $this->getSkinUrl('images/grid-cal.gif'),
    'required' => true,
    'label' => Mage::helper('vendor_module')->__('Start Date'),
    'title' => Mage::helper('vendor_module')->__('Start Date'),
    'style' => 'width: 120px',
));
$fieldsetRefInfo->addField('expire_date', 'date', array(
    'name' => 'expire_date',
    'input_format' => Varien_Date::DATETIME_INTERNAL_FORMAT,
    'format' => $dateTimeFormatIso,
    'time' => true,
    'image' => $this->getSkinUrl('images/grid-cal.gif'),
    'required' => true,
    'label' => Mage::helper('vendor_module')->__('Expiration Date'),
    'title' => Mage::helper('vendor_module')->__('Expiration Date'),
    'style' => 'width: 120px',
));

When I get the data back in my controller upon save, the start_date field comes back as string, but the expire_date field comes back as an array with no values:

$data['start_date'] = '3/5/18 5:46 PM';
$data['expire_date'] = ['from' => '', 'to' => '', 'local' => 'en_US'];

I'm assuming there's some JS going on in the background that is transforming the data, since the $_POST data comes back the same way.

Any ideas as to where I can start looking for this data transformation?

[EDIT - Here is the full form code]

protected function _prepareForm()
{
    $form = new Varien_Data_Form();
    $form->setHtmlIdPrefix('subscription_');

    $formData = $this->_getFormData();

    $fieldsetRefInfo = $form->addFieldset('vendor_module_reference_info', array(
        'legend' => Mage::helper('vendor_module')->__('Subscription Information')
    ));

    $fieldsetRefInfo->addField('status', 'label', array(
        'label' => Mage::helper('vendor_module')->__('Status'),
        'title' => Mage::helper('vendor_module')->__('Status'),
        'name' => 'status',
    ));

    $fieldsetRefInfo->addType('converted_date', 'Vendor_Module_Block_Adminhtml_Sales_Subscription_Edit_Element_Datetime');
    $fieldsetRefInfo->addField('created_at', 'converted_date', array(
        'name' => 'created_at',
        'label' => Mage::helper('vendor_module')->__('Created Date'),
        'title' => Mage::helper('vendor_module')->__('Created Date'),
    ));

    $dateTimeFormatIso = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
    $fieldsetRefInfo->addField('start_date', 'date', array(
        'name' => 'start_date',
        'input_format' => Varien_Date::DATETIME_INTERNAL_FORMAT,
        'format' => $dateTimeFormatIso,
        'time' => true,
        'image' => $this->getSkinUrl('images/grid-cal.gif'),
        'required' => true,
        'label' => Mage::helper('vendor_module')->__('Start Date'),
        'title' => Mage::helper('vendor_module')->__('Start Date'),
        'style' => 'width: 120px',
    ));
    $fieldsetRefInfo->addField('expire_date', 'date', array(
        'name' => 'expire_date',
        'input_format' => Varien_Date::DATETIME_INTERNAL_FORMAT,
        'format' => $dateTimeFormatIso,
        'time' => true,
        'image' => $this->getSkinUrl('images/grid-cal.gif'),
        'required' => true,
        'label' => Mage::helper('vendor_module')->__('Expiration Date'),
        'title' => Mage::helper('vendor_module')->__('Expiration Date'),
        'style' => 'width: 120px',
    ));

    // customer info
    $fieldsetCustomer = $form->addFieldset('vendor_module_customer_info', array(
        'legend' => Mage::helper('vendor_module')->__('Customer Information')
    ));

    $fieldsetCustomer->addField('customer_id', 'label', array(
        'label' => Mage::helper('vendor_module')->__('Customer ID'),
        'title' => Mage::helper('vendor_module')->__('Customer ID'),
        'name' => 'customer_id',
    ));

    $customerLink = Mage::helper('adminhtml')->getUrl(
        'adminhtml/customer/edit',
        array('id' => $formData['customer_id'])
    );
    $fieldsetCustomer->addField('customer_name', 'link', array(
        'label' => Mage::helper('vendor_module')->__('Name'),
        'title' => Mage::helper('vendor_module')->__('Name'),
        'name' => 'customer_name',
        'href' => $customerLink,
    ));

    // product info
    $fieldsetProduct = $form->addFieldset('vendor_module_product', array(
        'legend' => Mage::helper('vendor_module')->__('Product Details')
    ));

    $productLink = Mage::helper('adminhtml')->getUrl(
        'adminhtml/catalog_product/view',
        array('product_id' => $formData['final_product_id'])
    );

    $fieldsetProduct->addField('product_sku', 'label', array(
        'label' => Mage::helper('vendor_module')->__('SKU'),
        'title' => Mage::helper('vendor_module')->__('SKU'),
        'name' => 'product_sku',
    ));

    $form->addValues($formData);
    $this->setForm($form);
    return parent::_prepareForm();
}
  • Can you add your full form code? – Priyank Mar 16 '18 at 9:09
  • Just added the _prepareForm method. – Laura Mar 16 '18 at 15:16
3
+50

Make sure you don't have any other tabs in the form that are POSTing with the same input name as "expire_date".

  • 1
    Turns out I had a grid filter with the same form field name in a tab. – Laura Mar 16 '18 at 18:06

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.