Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Post array is empty on Custom Module form
 
babberoo
Jr. Member
 
Total Posts:  29
Joined:  2009-07-07
Cheltenham, England
 

I’ve got a custom module which shows a form on the frontend:

form.phtml

<form id="prescriptionForm" name="prescriptionForm" action="<?php echo $this->getFormAction(); ?>" method="post">

<
input id="form_key" name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" /> 
etc
</form>

My post action is http://192.168.254.50:81/COMPANY/index.php/prescription/index/post/

which correctly fires the postAction in my controller

IndexController.php

public function indexAction()
    
{
        $this
->loadLayout();
        
$this->getLayout()->getBlock('prescription')
            ->
setFormActionMage::getUrl('*/*/post') );

        
$this->_initLayoutMessages('customer/session');
        
$this->_initLayoutMessages('catalog/session');
        
$this->renderLayout();
    
}

public function postAction() {
        
if ($this->getRequest()->isPost()) {
            $data 
$this->getRequest()->getPost();
            
$prescription Mage::getModel('prescription/prescription');    

            
$prescription->setData($data)

            
                
// Do other setting in here as well
                
->setData('title'$this->getRequest()->getPost('title'))
                ->
setData('sph_left'$this->getRequest()->getPost('sph_left'))
                ->
setData('sph_right'$this->getRequest()->getPost('sph_right'))
                ->
setData('cyl_left'$this->getRequest()->getPost('cyl_left'))
                ->
setData('cyl_right'$this->getRequest()->getPost('cyl_right'))
                ->
setId(null);


etc

However, $this->getRequest-getPost() is empty. I’ve also tried $_POST but there is no data in the form. What am I missing?

 
Magento Community Magento Community
Magento Community
Magento Community
 
babberoo
Jr. Member
 
Total Posts:  29
Joined:  2009-07-07
Cheltenham, England
 

Ahhhh - It’s always something simple!

My form.phtml elements had id attributes but no name attributes. Adding in identical name="” attributes now passes them through to the postAction method.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top