2

我在 magento adminhtml 表单中有以下字段。

我的表单中的字段

在提交时,我希望抓住帖子,然后简单地转储其内容,这在我的 saveAction 中进行。

public function saveAction()
{
    if ($this->getRequest()->getPost())
    {
        try{
            $postData = $this->getRequest()->getPost();
            echo '<pre>';
            print_r($postData);
            exit;

输出如下所示。

Array
(
    [form_key] => I6jK6swe1EMl0wER
    [carrier_code] => test
    [postcode] => tescode
    [sku] => 123445
)

看到我的表格被定义为:

$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('instance_form', array('legend'=>Mage::helper('instance')->__('Instance Filters')));

    $fieldset->addField('carrier_code', 'text', array(
            'label'     => Mage::helper('instance')->__('Carrier service'),
            'name'      => 'carrier_code',
            'after_element_html' => '<small>Leave blank for all Carriers.</small>',
    ));
    
    $fieldset->addField('postcode', 'text', array(
            'label'     => Mage::helper('instance')->__('Postcode'),
            'name'      => 'postcode',
            'after_element_html' => '<small>Leave blank for all Postcodes.</small>',
    ));
    
    $fieldset->addField('sku', 'text', array(
            'label'     => Mage::helper('instance')->__('Sku'),
            'name'      => 'sku',
            'after_element_html' => '<small>Leave blank for all Skus.</small>',
    ));
    
    $fieldset->addField('start_date', 'date', array(
            'label'     => Mage::helper('instance')->__('Start Date'),
            'after_element_html' => '<small>Comments</small>',
            'tabindex' => 1,
            'image' => $this->getSkinUrl('images/grid-cal.gif'),
            'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)
    ));
    
    $fieldset->addField('aura', 'file', array(
            'label'     => Mage::helper('instance')->__('Upload'),
            'value'  => 'Uplaod',
            'disabled' => false,
            'readonly' => true,
            'after_element_html' => '<small>Comments</small>',
            'tabindex' => 1
    ));

我期待看到这样的输出:

Array
(
    [form_key] => I6jK6swe1EMl0wER
    [carrier_code] => test
    [postcode] => tescode
    [sku] => 123445
    [start_date] => someValue
    [aura] => anotherValue

)

我错过了什么吗?为什么会说日期字段,而不是像所有其他文本输入字段一样添加到帖子中?

干杯

4

1 回答 1

4

您在通话中丢失了name密钥。addField('start_date', ..)

Varien_Data_Form您希望提交的每个字段都需要一个name键/值对。

您分配给字段name键的值name<input>呈现<form>.

于 2012-05-25T10:57:39.063 回答