2
votes

I have the following fields in a magento adminhtml form.

The fields within my form

On submit im expecting to grab the post, and simply dump its contents, which im doing in my saveAction.

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

the output looks as follows.

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

Seeing my form is defined as:

$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
    ));

I was expecting to see output like this instead :

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

)

am i missing something? why would say the date field, not be added to the post, like all the other text input fields?

Cheers

1
Curious to know what a dump of $_POST is if you remove the tabindex properties.benmarks
Where's the name key of start_date?Jürgen Thelen
if i remove the tabindex property, the outcome is exactly the same. i added the name key and then found it to be present in the post!activeDev
another case of needing a second pair of eyes. thanks very much. can you submit an answer stating that to add fields to a form and expect it to be part of the past, it must have a name key. and thanks, i will mark this as correct obviously.activeDev

1 Answers

4
votes

You're missing the name key in your addField('start_date', ..) call.

Each field of a Varien_Data_Form you want to be submittable needs a name key/value pair.

The value you assign to your field's name key is used as value for the name attribute of the corresponding <input> element when rendering the <form>.