我在\ themes \ classic \ modules \ contactform \ views \ templates \ widget \ contactform.tpl的布局中添加了3个字段,它们显示完美。
我将这3个字段添加到DB表customer_thread。
除3个新字段外,联系请求将保存到此表中。
我还改变了
中的CustomerThread.php类public static $definition = array(
'table' => 'customer_thread',
'primary' => 'id_customer_thread',
'fields' => array(
'id_lang' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_contact' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'id_customer' =>array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'id_order' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'id_product' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'size' => 254),
'tel' => array('type' => self::TYPE_STRING, 'validate' => 'isString', 'size' => 254),
'naam' => array('type' => self::TYPE_STRING, 'validate' => 'isString', 'size' => 254),
'voornaam' => array('type' => self::TYPE_STRING, 'validate' => 'isString', 'size' => 254),
'token' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true),
'status' => array('type' => self::TYPE_STRING),
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
),
);
3个新字段是tel,naam和voornaam。
我错过了什么?
答案 0 :(得分:0)
定义其可见性:
public $tel;
public $naam;
$public $voornaam;
在定义之前的CustomerThread
类中的。
答案 1 :(得分:0)
此时,模型是正确的,数据库匹配......但您仍然没有获得表单值。
必须转到modules / contactform / contactform.php(ps 1.7)并找到公共函数sendMessage()
public function sendMessage()
{
$extension = array('.txt', '.rtf', '.doc', '.docx', '.pdf', '.zip', '.png', '.jpeg', '.gif', '.jpg');
$file_attachment = Tools::fileAttachment('fileUpload');
$message = Tools::getValue('message');
//Add Here
$tel = Tools::getValue('tel');
$naam = Tools::getValue('naam');
$voornaam = Tools::getValue('voornaam');
//make your validations if needed
if (!($from = trim(Tools::getValue('from'))) || !Validate::isEmail($from)) {
$this->context->controller->errors[] = $this->trans('Invalid email address.', array(), 'Shop.Notifications.Error');
} elseif (!$message) {
$this->context->controller->errors[] = $this->trans('The message cannot be blank.', array(), 'Shop.Notifications.Error');
} elseif (!Validate::isCleanHtml($message)) {
$this->context->controller->errors[] = $this->trans('Invalid message', array(), 'Shop.Notifications.Error');
} elseif (!($id_contact = (int)Tools::getValue('id_contact')) || !(Validate::isLoadedObject($contact = new Contact($id_contact, $this->context->language->id)))) {
$this->context->controller->errors[] = $this->trans('Please select a subject from the list provided. ', array(), 'Modules.Contactform.Shop');
} elseif (!empty($file_attachment['name']) && $file_attachment['error'] != 0) {
$this->context->controller->errors[] = $this->trans('An error occurred during the file-upload process.', array(), 'Modules.Contactform.Shop');
} elseif (!empty($file_attachment['name']) && !in_array(Tools::strtolower(substr($file_attachment['name'], -4)), $extension) && !in_array(Tools::strtolower(substr($file_attachment['name'], -5)), $extension)) {
$this->context->controller->errors[] = $this->trans('Bad file extension', array(), 'Modules.Contactform.Shop');
} else {
$customer = $this->context->customer;
if (!$customer->id) {
$customer->getByEmail($from);
}
$id_order = (int)Tools::getValue('id_order');
$id_customer_thread = CustomerThread::getIdCustomerThreadByEmailAndIdOrder($from, $id_order);
if ($contact->customer_service) {
if ((int)$id_customer_thread) {
$ct = new CustomerThread($id_customer_thread);
$ct->status = 'open';
$ct->id_lang = (int)$this->context->language->id;
$ct->id_contact = (int)$id_contact;
$ct->id_order = (int)$id_order;
if ($id_product = (int)Tools::getValue('id_product')) {
$ct->id_product = $id_product;
}
$ct->update();
} else {
$ct = new CustomerThread();
if (isset($customer->id)) {
$ct->id_customer = (int)$customer->id;
}
$ct->id_shop = (int)$this->context->shop->id;
$ct->id_order = (int)$id_order;
if ($id_product = (int)Tools::getValue('id_product')) {
$ct->id_product = $id_product;
}
$ct->id_contact = (int)$id_contact;
$ct->id_lang = (int)$this->context->language->id;
$ct->email = $from;
//Add Here
$ct->tel = $tel;
$ct->naam = $naam;
$ct->voornaam = $voornaam;
$ct->status = 'open';
$ct->token = Tools::passwdGen(12);
$ct->add();
}//......etc