Frage

Ich entwickle ein benutzerdefiniertes Magento (1.9) -Modul und habe im Administrator ein Formular zum Hinzufügen / Bearbeiten einer Entität namens "Abonnement" erstellt.Dadurch wird entweder ein neues Abonnementobjekt erstellt oder ein vorhandenes Abonnementobjekt bearbeitet.

Folgendes ist mein SubscriptionController.php

<?php

class Beyondroid_Subscribepro_Adminhtml_SubscriptionsController extends Mage_Adminhtml_Controller_Action {

    public function indexAction() {
        $subscriptionsBlock = $this->getLayout()
            ->createBlock('beyondroid_subscribepro_adminhtml/subscriptions');

        $this->loadLayout();
        $this->_setActiveMenu('beyondroid_subscribepro');
        $this->_addContent($subscriptionsBlock);
        $this->getLayout()->getBlock('head')->setTitle($this->__('Beyondroid SubscribePro - Subscriptions'));
        $this->renderLayout();
    }

    public function editAction() {
        $subscription = Mage::getModel('subscribepro/subscriptions');
        if ($subscriptionId = $this->getRequest()->getParam('id', false)) {
            $subscription->load($subscriptionId);
            if (!($subscription->getId())) {
                $this->_getSession()->addError(
                    $this->__('This subscription no longer exists.')
                );
            }
        }

        //var_dump($this->getRequest()->getPost());
        /**
        if ($postData = $this->getRequest()->getPost('subscriptionsData')) {
            try {
                $subscription->addData($postData);
                $subscription->save();

                $this->_getSession()->addSuccess(
                    $this->__('Subscription data was updated')
                );
                return $this->_redirect(
                    'adminhtml/subscriptions/edit', array('id' => $subscription->getId())
                );
            } catch (Exception $e) {
                Mage::logException($e);
                $this->_getSession->addError($e->getMessage());
            }
        }
        **/
        Mage::register('current_subscription', $subscription);
        $subscriptionEditBlock = $this->getLayout()->createBlock(
            'beyondroid_subscribepro_adminhtml/subscriptions_edit'
        );

        $this->loadLayout()
            ->_addContent($subscriptionEditBlock)
            ->renderLayout();
    }

    public function saveAction() {
        var_dump($this->getRequest()->getPost());
        die();
    }

    protected function _isAllowed() {
        $actionName = $this->getRequest()->getActionName();
        $adminSession = Mage::getSingleton('admin/session');
        $isAllowed = $adminSession->isAllowed('beyondroid_subscribepro/subscriptions');
        return $isAllowed;
    }
}

und hier ist der Subscriptions/Edit/Form.php

class Beyondroid_Subscribepro_Block_Adminhtml_Subscriptions_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',
            'enctype' => 'multipart/form-data',
        ));
        $form->setUseContainer(true);

        $fieldset = $form->addFieldSet(
            'general',
            array('legend' => 'Subscription Details')
        );

        $currentSubscription = $this->_getSubscription();

        $fieldset->addField('product_id', 'text', array(
            'label' => 'Product ID',
            'required' => true,
            'note' => 'This resembles the product ID for this subscription',
        ));
        $fieldset->addField('deliveries', 'text', array(
            'label' => 'No. of deliveries (in a month)',
            'required' => true,
            'note' => 'This resembles the number of deliveries to be made for this kind of a subscription in one month',
        ));
        $fieldset->addField('unit_price', 'text', array(
            'label' => 'Unit Price',
            'required' => true,
            'note' => 'This defines how much each delivery costs',
        ));

        $form->setValues($currentSubscription->getData());
        $this->setForm($form);
        return parent::_prepareForm();
    }

    protected function _getSubscription() {
        if (!$this->hasData('subscriptions')) {
            $subscription = Mage::registry('current_subscription');
            if (!$subscription instanceof
                    Beyondroid_Subscribepro_Model_Subscriptions) {
                $subscription = Mage::getModel(
                    'beyondroid_subscribepro/subscriptions'
                );
            }
            $this->setData('subscription', $subscription);
        }
        return $this->getData('subscription');
    }
}

Form Loaded

Das Formular wird in beiden Fällen neu / Bearbeiten ordnungsgemäß geladen (wie im obigen Bild zu sehen ist).Das Problem ist, wenn ich versuche, das Formular zu speichern, erhalte ich keine Post-Daten.Wenn Sie auf die Schaltfläche Speichern klicken, wird die Route zum saveAction methode in meinem Controller, aber die Post-Daten sind ein Array mit nur 1 Schlüsselwertpaar, dh. form_key => 'some random string'.

Folgendes ist was var_dump erklärung in saveAction methode gibt zurück:

No Post Data

Irgendwelche Ideen, was mir hier fehlt?

Update

Das Folgende ist, was ich in der Anforderungsnutzlast sehe, dh.fehlende Beitragsdaten: O

enter image description here

Aktualisierung 2

Die HTML-Struktur des Formulars sieht gut aus.Die Felder befinden sich innerhalb der <form></form> tags und nur 1 Formular auf der Seite.

enter image description here

War es hilfreich?

Lösung

Auf Ihrem letzten Screenshot sehe ich, dass die Felder, die Sie einreichen, keinen Namen haben.

Schau dir die Eingabe mit der ID an product_id beispielsweise.der name attribut ist leer.

Ich denke, das Problem liegt in der Art und Weise, wie Sie Ihre Felder definiert haben.

Nehmen wir das zum Beispiel:

   $fieldset->addField('product_id', 'text', array(
        'label' => 'Product ID',
        'required' => true,
        'note' => 'This resembles the product ID for this subscription',
    ));

Es gibt keine name attribut im Konfigurationsarray.
es sollte ungefähr so sein:

   $fieldset->addField('product_id', 'text', array(
        'name' => 'product_id', //you are missing this in your code
        'label' => 'Product ID',
        'required' => true,
        'note' => 'This resembles the product ID for this subscription',
    ));

machen Sie dasselbe für die anderen Felder und versuchen Sie es erneut.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange
scroll top