Reputation: 21
I added 3 fields to the layout at \themes\classic\modules\contactform\views\templates\widget\contactform.tpl and they show up perfect.
I added these 3 fields to the DB table customer_thread.
Contact requests are saved into this table except for the 3 new fields.
I also changed the CustomerThread.php class in
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'),
),
);
The 3 new fields are tel, naam and voornaam.
What am I missing ?
Upvotes: 2
Views: 2658
Reputation: 11
At this point, the model is right, database matches... but you still are not getting the form values.
Must go to modules/contactform/contactform.php (ps 1.7) and find public function 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
Upvotes: 1
Reputation: 1022
Define its visibility:
public $tel;
public $naam;
$public $voornaam;
in CustomerThread
class, before the definition.
Upvotes: 1