I keep getting the error mentioned in the title when trying to submit a form that contains a customer message. It is a form that when submitted is supposed to save the info in the database. Here is the function
public function formPostAction()
{
if (!$this->_validateFormKey()) {
return $this->_redirect('*/*/');
}
// Save data
if ($this->getRequest()->isPost()) {
$data = $this->getRequest()->getPost();
$customerId = $this->_getSession()->getCustomer()->getId();
$message = Mage::getModel('hwcustomer/message')
->setData($data)
->setMessage($data['message'])
->setSubject($data['subject'])
->setParentId($customerId);
$messageId = $this->getRequest()->getParam('id');
$message->setId(null);
if ($messageId) {
$customerMessage = Mage::getModel('hwcustomer/message')->load($messageId);
if ($customerMessage->getId() && $customerMessage->getCustomerId() == $this->_getSession()->getCustomerId()) {
$message->setId($messageId);
}
}
try {
$messageValidation = $message->validateMessage($data);
if (empty($messageValidation)) {
$message->save();
$this->_getSession()->addSuccess($this->__('The message was successfully saved'));
$this->_redirectSuccess(Mage::getUrl('customer/messages', array('_secure'=>true)));
return;
} else {
if (is_array($messageValidation)) {
foreach ($messageValidation as $errorMessage) {
$this->_getSession()->addError($errorMessage);
}
} else {
$this->_getSession()->addError($this->__('Can\'t save message'));
}
}
}
}
}