Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento-在管理面板中创建新表单,但“保存”按钮不起作用_Magento - Fatal编程技术网

Magento-在管理面板中创建新表单,但“保存”按钮不起作用

Magento-在管理面板中创建新表单,但“保存”按钮不起作用,magento,Magento,我正在使用Magento 1.9.0.1,目前正在使用自定义扩展 我在管理面板中创建了一个自定义编辑表单,下面是它的屏幕截图: Save Item按钮就像死了一样。当我点击它时,什么都没有发生,没有错误,甚至没有页面加载/重新加载。。。。没什么 Delete Item按钮工作正常,正在删除必须删除的内容 以下是我认为应对我的挣扎负责的代码: 我这里是我的Edit.php: <?php class VivasIndustries_SmsNotification_Block_Adminhtm

我正在使用Magento 1.9.0.1,目前正在使用自定义扩展

我在管理面板中创建了一个自定义编辑表单,下面是它的屏幕截图:

Save Item
按钮就像死了一样。当我点击它时,什么都没有发生,没有错误,甚至没有页面加载/重新加载。。。。没什么

Delete Item
按钮工作正常,正在删除必须删除的内容

以下是我认为应对我的挣扎负责的代码:

我这里是我的Edit.php:

<?php
class VivasIndustries_SmsNotification_Block_Adminhtml_Sms_Status_Edit extends Mage_Adminhtml_Block_Widget_Form_Container

{
    public function __construct()
    {
        parent::__construct();

        $this->_objectId = 'id';
        $this->_blockGroup = 'smsnotification';
        $this->_controller = 'adminhtml_sms_status';

        $this->_updateButton('save', 'label', Mage::helper('smsnotification')->__('Save Item'));
        $this->_updateButton('delete', 'label', Mage::helper('smsnotification')->__('Delete Item'));
    }

    public function getHeaderText()
    {
        if( Mage::registry('smsnotification_data') && Mage::registry('smsnotification_data')->getId() ) {
            return Mage::helper('smsnotification')->__("Edit Item '%s'", $this->htmlEscape(Mage::registry('smsnotification_data')->getTitle()));
        } else {
            return Mage::helper('smsnotification')->__('Add Item');
        }
    }
}

我知道这个问题现在已经很老了,但是对于遇到这个问题的人来说,我也遇到了同样的问题,只是我必须确保我的表单ID是
编辑表单

它出现在OP的代码中,他需要添加
$form->setUseContainer(true)
$this->setForm($form)之前


希望这对其他人有所帮助。

您确信saveAction()已执行吗?您可以转储$postData和$smsnotificationModel(在设置值之后)?当您单击“保存”时,您是否在控制台中看到Javascript错误?似乎根本没有执行
saveAction()
,因为我说过没有错误,没有加载或重新加载页面。这个按钮就像一个简单的图像,当你点击它时,什么也没有发生。但是,
Delete
按钮工作正常。对不起,我读了这篇文章并添加了我的第二条评论:)按钮的HTML代码是否显示了正确的操作?我认为它正常:
Save Item
<?php
class VivasIndustries_SmsNotification_Block_Adminhtml_Sms_Status_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
    {


        protected function _prepareForm()
            {
                $form = new Varien_Data_Form(array(
                                        'id' => 'edit_form',
                                        'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
                                        'method' => 'post',
                                     ));
                $this->setForm($form);
                $fieldset = $form->addFieldset('smsnotification_form', array('legend'=>Mage::helper('smsnotification')->__('Item information')));

                $fieldset->addField('Receiver', 'text', array(
                    'label'     => Mage::helper('smsnotification')->__('Receiver'),
                    'class'     => 'required-entry',
                    'required'  => true,
                    'name'      => 'Receiver',
                     ));

                $fieldset->addField('Phone', 'text', array(
                    'label'     => Mage::helper('smsnotification')->__('Phone'),
                    'class'     => 'required-entry',
                    'required'  => true,
                    'name'      => 'Phone',
                    ));

                $fieldset->addField('Date', 'text', array(
                    'label'     => Mage::helper('smsnotification')->__('Date'),
                    'class'     => 'required-entry',
                    'required'  => true,
                    'name'      => 'Date',
                    ));

                if ( Mage::getSingleton('adminhtml/session')->getsmsnotificationData() )
                    {
                        $form->setValues(Mage::getSingleton('adminhtml/session')->getsmsnotificationData());
                        Mage::getSingleton('adminhtml/session')->setsmsnotificationData(null);
                    } elseif ( Mage::registry('smsnotification_data') ) {
                        $form->setValues(Mage::registry('smsnotification_data')->getData());
                    }
                    return parent::_prepareForm();
            }
    }
<?php

class VivasIndustries_SmsNotification_Block_Adminhtml_Sms_Status extends Mage_Adminhtml_Block_Widget_Grid_Container


{
    public function __construct()
    {
        $this->_controller = 'adminhtml_sms_status';
        $this->_blockGroup = 'smsnotification';
        $this->_headerText = Mage::helper('smsnotification')->__('Item Manager');
        $this->_addButtonLabel = Mage::helper('smsnotification')->__('Add Item');
        parent::__construct();
    }
}
<?php

class VivasIndustries_SmsNotification_Adminhtml_SmsorderstatusesController extends Mage_Adminhtml_Controller_Action
{
    public function indexAction()
    {
        $this->_title($this->__('SMS Center'))->_title($this->__('SMS Center'));
        $this->loadLayout();
        $this->_setActiveMenu('vivassms');
        $this->_addContent($this->getLayout()->createBlock('smsnotification/adminhtml_sms_status'));
        $this->renderLayout();
    }

    public function editAction()
    {
        $smsnotificationId     = $this->getRequest()->getParam('id');
        $smsnotificationModel  = Mage::getModel('smsnotification/smsnotification')->load($smsnotificationId);

        if ($smsnotificationModel->getId() || $smsnotificationId == 0) {

            Mage::register('smsnotification_data', $smsnotificationModel);

            $this->loadLayout();
            $this->_setActiveMenu('smsnotification/items');

            $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
            $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));

            $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);

            $this->_addContent($this->getLayout()->createBlock('smsnotification/adminhtml_sms_status_edit'));

            $this->renderLayout();
        } else {
            Mage::getSingleton('adminhtml/session')->addError(Mage::helper('smsnotification')->__('Item does not exist'));
            $this->_redirect('*/*/');
        }
    }

    public function newAction()
    {
        $this->_forward('edit');
    }

    public function saveAction()
    {
        if ( $this->getRequest()->getPost() ) {
            try {
                $postData = $this->getRequest()->getPost();
                $smsnotificationModel = Mage::getModel('smsnotification/smsnotification');

                $smsnotificationModel->setId($this->getRequest()->getParam('id'))
                    ->setReceiver($postData['Receiver'])
                    ->setPhone($postData['Phone'])
                    ->setDate($postData['Date'])
                    ->save();

                Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully saved'));
                Mage::getSingleton('adminhtml/session')->setsmsnotificationData(false);

                $this->_redirect('*/*/');
                return;
            } catch (Exception $e) {
                Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
                Mage::getSingleton('adminhtml/session')->setsmsnotificationData($this->getRequest()->getPost());
                $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
                return;
            }
        }
        $this->_redirect('*/*/');
    }

    public function deleteAction()
    {
        if( $this->getRequest()->getParam('id') > 0 ) {
            try {
                $smsnotificationModel = Mage::getModel('smsnotification/smsnotification');

                $smsnotificationModel->setId($this->getRequest()->getParam('id'))
                    ->delete();

                Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully deleted'));
                $this->_redirect('*/*/');
            } catch (Exception $e) {
                Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
                $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
            }
        }
        $this->_redirect('*/*/');
    }
    /**
     * Product grid for AJAX request.
     * Sort and filter result for example.
     */
    public function gridAction()
    {
        $this->loadLayout();
        $this->getResponse()->setBody(
               $this->getLayout()->createBlock('smsnotification/adminhtml_smsnotification_grid')->toHtml()
        );
    }
}
<?xml version="1.0"?>
<config>
  <modules>
    <VivasIndustries_SmsNotification>
      <version>0.1.0</version>
    </VivasIndustries_SmsNotification>
  </modules>
  <global>
    <models>
        <smsnotification>
            <class>VivasIndustries_SmsNotification_Model</class>
            <resourceModel>vivasindustries_smsnotification_resource</resourceModel>
        </smsnotification>
        <vivasindustries_smsnotification_resource>
        <class>VivasIndustries_SmsNotification_Model_Resource</class>
        <entities>
            <smsnotification>
            <table>VivasIndustries_SmsNotification</table>
            </smsnotification>
        </entities>
        </vivasindustries_smsnotification_resource>
    </models>
    <resources>
        <smsnotification_setup>
            <setup>
                <module>VivasIndustries_SmsNotification</module>
            </setup>
            <connection>
                 <use>core_setup</use>
             </connection>
        </smsnotification_setup>
        <smsnotification_read>
            <connection>
                <use>core_read</use>
            </connection>
        </smsnotification_read>
        <smsnotification_write>
            <connection>
                <use>core_write</use>
            </connection>
        </smsnotification_write>
    </resources>    
    <events>
        <sales_order_save_after>
            <observers>
                <vivasindustries_smsnotification>
                    <class>smsnotification/observer</class>
                    <method>orderSaved</method>
                </vivasindustries_smsnotification>
            </observers>
        </sales_order_save_after>
    </events>
    <helpers>
        <smsnotification>
            <class>VivasIndustries_SmsNotification_Helper</class>
        </smsnotification>
    </helpers>
    <blocks>
        <smsnotification>
             <class>VivasIndustries_SmsNotification_Block</class>
        </smsnotification>
    </blocks>
  </global>
  <adminhtml>
    <acl>
        <resources>
            <all>
                <title>Allow Everything</title>
            </all>
            <admin>
                <children>
                    <system>
                        <children>
                            <config>
                                <children>
                                    <vivas>
                                        <title>Vivas - All</title>
                                    </vivas>
                                </children>
                            </config>
                        </children>
                    </system>
                </children>
            </admin>
        </resources>
    </acl>
    <layout>
        <updates>
            <smsnotification>
                <file>smsnotification.xml</file>
            </smsnotification>
        </updates>
    </layout>   
    </adminhtml>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <VivasIndustries_SmsNotification before="Mage_Adminhtml">VivasIndustries_SmsNotification_Adminhtml</VivasIndustries_SmsNotification>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
</config>