Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 337 Vote(s) - 3.59 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prestashop 1.7.2: add 3 fields to contact us page

#1
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 ?
Reply

#2
Define its visibility:

public $tel;
public $naam;
$public $voornaam;

in `CustomerThread` class, before the definition.
Reply

#3
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
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through