I have this error after i try to save data from my admin grid. How to fix this error.
Exception #0 (Exception): Warning: Undefined array key "card_pin" in /var/www/html/rakuten_magento/app/code/Rakuten/MemberCard/Controller/Adminhtml/Card/Save.php on line 36
Exception #0 (Exception): Warning: Undefined array key "card_pin" in /var/www/html/rakuten_magento/app/code/Rakuten/MemberCard/Controller/Adminhtml/Card/Save.php on line 36
<pre>#1 Rakuten\MemberCard\Controller\Adminhtml\Card\Save->execute() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#2 Rakuten\MemberCard\Controller\Adminhtml\Card\Save\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#3 Rakuten\MemberCard\Controller\Adminhtml\Card\Save\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#4 Rakuten\MemberCard\Controller\Adminhtml\Card\Save\Interceptor->___callPlugins() called at [generated/code/Rakuten/MemberCard/Controller/Adminhtml/Card/Save/Interceptor.php:23]
#5 Rakuten\MemberCard\Controller\Adminhtml\Card\Save\Interceptor->execute() called at [vendor/magento/framework/App/Action/Action.php:111]
#6 Magento\Framework\App\Action\Action->dispatch() called at [vendor/magento/module-backend/App/AbstractAction.php:151]
#7 Magento\Backend\App\AbstractAction->dispatch() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#8 Rakuten\MemberCard\Controller\Adminhtml\Card\Save\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#9 Rakuten\MemberCard\Controller\Adminhtml\Card\Save\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/module-backend/App/Action/Plugin/Authentication.php:145]
#10 Magento\Backend\App\Action\Plugin\Authentication->aroundDispatch() called at [vendor/magento/framework/Interception/Interceptor.php:135]
#11 Rakuten\MemberCard\Controller\Adminhtml\Card\Save\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#12 Rakuten\MemberCard\Controller\Adminhtml\Card\Save\Interceptor->___callPlugins() called at [generated/code/Rakuten/MemberCard/Controller/Adminhtml/Card/Save/Interceptor.php:32]
#13 Rakuten\MemberCard\Controller\Adminhtml\Card\Save\Interceptor->dispatch() called at [vendor/magento/framework/App/FrontController.php:245]
#14 Magento\Framework\App\FrontController->getActionResponse() called at [vendor/magento/framework/App/FrontController.php:212]
#15 Magento\Framework\App\FrontController->processRequest() called at [vendor/magento/framework/App/FrontController.php:147]
#16 Magento\Framework\App\FrontController->dispatch() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#17 Magento\Framework\App\FrontController\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#18 Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#19 Magento\Framework\App\FrontController\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/App/FrontController/Interceptor.php:23]
#20 Magento\Framework\App\FrontController\Interceptor->dispatch() called at [vendor/magento/framework/App/Http.php:116]
#21 Magento\Framework\App\Http->launch() called at [vendor/magento/framework/App/Bootstrap.php:264]
#22 Magento\Framework\App\Bootstrap->run() called at [pub/index.php:30]
</pre>
Here is my controller Save file:
public function execute()
{
$data = $this->getRequest()->getPostValue();
$id = !empty($data['entity_id']) ? $data['entity_id'] : null;
$newData = [
'card_pin' => $data['card_pin'],
'status' => $data['status'],
'content' => $data['content'],
];
$post = $this->postFactory->create();
if ($id) {
$post->load($id);
}
try {
$post->addData($newData);
$post->save();
$this->messageManager->addSuccessMessage(__('You saved the post.'));
} catch (\Exception $e) {
$this->messageManager->addErrorMessage(__($e->getMessage()));
}
return $this->resultRedirectFactory->create()->setPath('helloworld/card/index');
}