NemoPS Posted July 29, 2013 Share Posted July 29, 2013 Hi everybody! I received many requests to make a tutorial about adding new fields to the default contact form. Here it is! http://nemops.com/adding-new-fields-to-prestashop-contact-form/ Cheers! 2 1 Link to comment Share on other sites More sharing options...
mowax Posted August 23, 2013 Share Posted August 23, 2013 Thanks for this tutorial Nemo1, it is definitely needed! Link to comment Share on other sites More sharing options...
mowax Posted August 23, 2013 Share Posted August 23, 2013 (edited) Hi Nemo1, I have followed the steps, but have a problem. I am adding 2 extra fields, some have called them extrafield1 and extrafield2, and added them both to each step. But the values are not being passed to the database. I have pasted my file changes below, does anything look wrong to you? themes/default/contact_form.tpl <p class="text"> <label for="extrafield1">{l s='Your name'}</label> {if isset($customerThread.extrafield1)} <input type="text" id="extrafield1" name="extrafield1" value="{$customerThread.extrafield1|escape:'htmlall':'UTF-8'}" readonly="readonly" /> {else} <input type="text" id="extrafield1" name="extrafield1" value="" /> {/if} </p> then <p class="text"> <label for="extrafield2">{l s='Message subject'}</label> {if isset($customerThread.extrafield2)} <input type="text" id="extrafield2" name="extrafield2" value="{$customerThread.extrafield2|escape:'htmlall':'UTF-8'}" readonly="readonly" /> {else} <input type="text" id="extrafield2" name="extrafield2" value="" /> {/if} </p> override/classes/CustomerThread.php <?php class CustomerThread extends CustomerThreadCore { public $extrafield; 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), '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'), 'extrafield1' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'), 'extrafield2' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'), ), ); } override/controllers/front/ContactConroller.php 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); if ($id_order = (int)Tools::getValue('id_order')) $ct->id_order = $id_order; if ($id_product = (int)Tools::getValue('id_product')) $ct->id_product = $id_product; $ct->extrafield1 = Tools::getValue('extrafield1'); $ct->extrafield2 = Tools::getValue('extrafield2'); $ct->update(); } else { $ct = new CustomerThread(); if (isset($customer->id)) $ct->id_customer = (int)($customer->id); $ct->id_shop = (int)$this->context->shop->id; if ($id_order = (int)Tools::getValue('id_order')) $ct->id_order = $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; $ct->status = 'open'; $ct->token = Tools::passwdGen(12); $ct->extrafield1 = Tools::getValue('extrafield1'); $ct->extrafield2 = Tools::getValue('extrafield2'); $ct->add(); } if ($ct->id) then if (!count($this->errors)) { $var_list = array( '{order_name}' => '-', '{attached_file}' => '-', '{message}' => Tools::nl2br(stripslashes($message)), '{email}' => $from, '{extrafield1}' => (isset($ct) && $ct->extrafield1) ? $ct->extrafield1 : '', '{extrafield2}' => (isset($ct) && $ct->extrafield2) ? $ct->extrafield2 : '' ); Please see the attachment for the ps_customer_thread table settings Edited August 23, 2013 by duratex (see edit history) Link to comment Share on other sites More sharing options...
mowax Posted August 23, 2013 Share Posted August 23, 2013 (edited) I think I've just spotted my error... at the top of override/classes/CustomerThread.php, I have <?php class CustomerThread extends CustomerThreadCore { public $extrafield; I forgot to change public $extrafield; to public $extrafield# how would I arrange this? like <?php class CustomerThread extends CustomerThreadCore { public $extrafield1; public $extrafield2; 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), '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'), 'extrafield1' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'), 'extrafield2' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'), ), ); } Thanks for any advice! Edited August 29, 2013 by mowax (see edit history) Link to comment Share on other sites More sharing options...
mowax Posted August 29, 2013 Share Posted August 29, 2013 Hi Nemo1, I tried arranging them as per my previous post, but I'm obviously in over my head as it doesn't work. Do you have an idea how to modify override/classes/CustomerThread.php to add a second extrafield? Thanks for any help Mo Link to comment Share on other sites More sharing options...
NemoPS Posted August 30, 2013 Author Share Posted August 30, 2013 Hi there! What kind of error are you getting? Link to comment Share on other sites More sharing options...
mowax Posted August 30, 2013 Share Posted August 30, 2013 When I try adding both extrafield1 and 2 to CustomerThread.php as follows, the contact-us page doesn't load at all. <?php class CustomerThread extends CustomerThreadCore { public $extrafield1; public $extrafield2; Link to comment Share on other sites More sharing options...
jgullstr Posted August 30, 2013 Share Posted August 30, 2013 Nice tutorial! If you want to keep the core definitions you could also write the model override something like this: class CustomerThread extends CustomerThreadCore { public $extrafield; public function __construct($id = null, $id_lang = null, $id_shop = null){ self::$definition['fields']['extrafield'] = array( 'type' => self::TYPE_STRING, 'validate' => 'isGenericName', ); parent::__construct($id, $id_lang, $id_shop); } } (On a sidenote, most of PrestaShop's controllers are in a dire need of better functional cohesion, as overriding huge methods like postProcess in this case prevent core updates on those methods from taking effect) Link to comment Share on other sites More sharing options...
mowax Posted September 8, 2013 Share Posted September 8, 2013 Any ideas how to create more than one extra field? I tried as per my last post but I am having trouble with the CustomerThread.php file Link to comment Share on other sites More sharing options...
NemoPS Posted September 9, 2013 Author Share Posted September 9, 2013 Not loading at all? But are you getting any error if you enable them? It's really weird! Link to comment Share on other sites More sharing options...
mowax Posted September 9, 2013 Share Posted September 9, 2013 Hi, yup I just get a white screen. So does my CustomerThread.php file look right? (http://www.prestashop.com/forums/topic/264731-free-tutorial-adding-new-fields-to-the-contact-form/?view=findpost&p=1350152) Link to comment Share on other sites More sharing options...
panupat Posted September 14, 2013 Share Posted September 14, 2013 Thanks for the tutorial. Still, it's so much work just to add new fields... why isn't there a phone number field... it's so needed imo. Link to comment Share on other sites More sharing options...
mowax Posted September 14, 2013 Share Posted September 14, 2013 And you can only add 1 extra field. A lot of work for a small improvement! Link to comment Share on other sites More sharing options...
justicejustine Posted October 9, 2013 Share Posted October 9, 2013 (edited) Someone duplicated the tutorial here: http://blog.arvixe.com/adding-new-fields-to-the-prestashop-contact-form/ Just thought of letting you know. Edited October 9, 2013 by justicejustine (see edit history) Link to comment Share on other sites More sharing options...
alsitn Posted October 9, 2013 Share Posted October 9, 2013 (edited) Hi, Fabio is Nemo. Nemo is Fabio. No dupes EDIT: check this out http://blog.arvixe.com/author/nemo/ Edited October 9, 2013 by alsitn (see edit history) 1 Link to comment Share on other sites More sharing options...
zupermanzito Posted November 12, 2013 Share Posted November 12, 2013 Actually im getting the same error as @mowax, contact from hit a white page, and in the database the values are not being pasted. got ideas? Link to comment Share on other sites More sharing options...
pbpo Posted December 9, 2013 Share Posted December 9, 2013 (edited) Tutorial is great but i have problems with it . override/classes/CustomerThread.php ==> <?php class CustomerThread extends CustomerThreadCore { public $id_client; public $id_adress; public $id_comp; 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'), 'id_client' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'), 'id_adress' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'), 'id_comp' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'), 'status' => array('type' => self::TYPE_STRING), 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), ), ); } prestashop/controllers/ContactController.php 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); if ($id_order = (int)Tools::getValue('id_order')) $ct->id_order = $id_order; if ($id_product = (int)Tools::getValue('id_product')) $ct->id_product = $id_product; $ct->id_client = Tools::getValue('id_client'); $ct->id_adress = Tools::getValue('id_adress'); $ct->id_comp = Tools::getValue('id_comp'); $ct->update(); } else { $ct = new CustomerThread(); if (isset($customer->id)) $ct->id_customer = (int)($customer->id); $ct->id_shop = (int)$this->context->shop->id; if ($id_order = (int)Tools::getValue('id_order')) $ct->id_order = $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; $ct->status = 'open'; $ct->token = Tools::passwdGen(12); $ct->id_client = (string)Tools::getValue('id_client'); $ct->id_adress = (string)Tools::getValue('id_adress'); $ct->id_comp = (string)Tools::getValue('id_comp'); $ct->add(); } if ($ct->id) { $cm = new CustomerMessage(); $cm->id_customer_thread = $ct->id; $cm->message = Tools::htmlentitiesUTF8($message); if (isset($filename) && rename($_FILES['fileUpload']['tmp_name'], _PS_MODULE_DIR_.'../upload/'.$filename)) $cm->file_name = $filename; $cm->ip_address = ip2long($_SERVER['REMOTE_ADDR']); $cm->user_agent = $_SERVER['HTTP_USER_AGENT']; if (!$cm->add()) $this->errors[] = Tools::displayError('An error occurred while sending the message.'); } else $this->errors[] = Tools::displayError('An error occurred while sending the message.'); } if (!count($this->errors)) { $var_list = array( '{order_name}' => '-', '{attached_file}' => '-', '{message}' => Tools::nl2br(stripslashes($message)), '{email}' => $from, '{id_client}' => (isset($ct) && $ct->id_client) ? $ct->id_client : '', '{id_adress}' => (isset($ct) && $ct->id_adress) ? $ct->id_adress : '', '{id_comp}' => (isset($ct) && $ct->id_comp) ? $ct->id_comp : '', ); And when I want to send, I get an error. (e-mail is sent, but the error is displayed) Edited December 9, 2013 by pbpo (see edit history) Link to comment Share on other sites More sharing options...
wallchopz Posted July 29, 2014 Share Posted July 29, 2014 Hello Nemo1, Thank you so much for the tutorial. I have made everything work fine. I just need to know how to save the values of the text fields after the page refreshes when the form is validated. Thanks! Link to comment Share on other sites More sharing options...
tatamimi Posted September 19, 2014 Share Posted September 19, 2014 (edited) Hello Nemo1!Thank you for your good tutorial and advaices always!I tried to customize the contact form and it works fine!If possible I want know how to make a input area "required" and show the error if it is empty. (I use version 1.6.0.9) Thank you in advance! Edited September 19, 2014 by tatamimi (see edit history) Link to comment Share on other sites More sharing options...
pbpo Posted September 22, 2014 Share Posted September 22, 2014 Hello Nemo1! Thank you for your good tutorial and advaices always! I tried to customize the contact form and it works fine! If possible I want know how to make a input area "required" and show the error if it is empty. (I use version 1.6.0.9) Thank you in advance! Hi, Tatamimi I wanted too use this tutorial in Prestashop 1.6.0.9 but i have problem with mails. firstly I just created 2 extra fields , they are in: - contact.tpl - CustomerThread.php - ContactController.php - contact-form.tpl - In mails: > contact.html > contact-form.html Just as it is in this tutorial E-mail was sended correctly but when I see mail in my mail-program, fields are empty ( didn't downloaded fields content ) Could you send me yours files ? I want them to see and create my own my mail -> [email protected] Link to comment Share on other sites More sharing options...
tatamimi Posted September 23, 2014 Share Posted September 23, 2014 Hi pbpo!Did you add the database value ?Sorry I don't use the field of downloaded files in my case( I delated these contents from the mail and form ) so I don't know it works well at that point... In my case, {products} (the detail of order in the mail) didn't work at first.It was because of the change or controll files in the version 1.6.0.9. (I use override file made before 1.6.0.6)I copied the controlle files from 1.6.0.9 default template and added my code for add the contact form contents and upload again, after it works. Link to comment Share on other sites More sharing options...
pbpo Posted September 23, 2014 Share Posted September 23, 2014 (edited) Yes I add the database value. When mail is sent. Fields are empty. My files: contact-form.tpl <p class="form-group"> <label for="id_imie">{l s='id_imie'}</label> {if isset($customerThread.id_imie)} <input class="form-control grey" type="text" id="id_imie" name="id_imie" value="{$customerThread.id_imie|escape:'htmlall':'UTF-8'}" readonly="readonly" /> {else} <input class="form-control grey validate" type="text" id="id_imie" name="id_imie" value="" /> {/if} <p>(example: Jan)</p> </p> ContactController.php 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->id_imie = Tools::getValue('id_imie'); $ct->id_nazwisko = Tools::getValue('id_nazwisko'); $ct->id_organ = Tools::getValue('id_organ'); $ct->id_adres = Tools::getValue('id_adres'); $ct->id_poczta = Tools::getValue('id_poczta'); $ct->id_miasto = Tools::getValue('id_miasto'); $ct->id_telefon = Tools::getValue('id_telefon'); $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; $ct->status = 'open'; $ct->token = Tools::passwdGen(12); $ct->id_imie = Tools::getValue('id_imie'); $ct->id_nazwisko = Tools::getValue('id_nazwisko'); $ct->id_organ = Tools::getValue('id_organ'); $ct->id_adres = Tools::getValue('id_adres'); $ct->id_poczta = Tools::getValue('id_poczta'); $ct->id_miasto = Tools::getValue('id_miasto'); $ct->id_telefon = Tools::getValue('id_telefon'); $ct->add(); } if (!count($this->errors)) { $var_list = array( '{order_name}' => '-', '{attached_file}' => '-', '{message}' => Tools::nl2br(stripslashes($message)), '{email}' => $from, '{product_name}' => '', '{id_imie}' => (isset($ct) && $ct->id_imie) ? $ct->id_imie : '', '{id_nazwisko}' => (isset($ct) && $ct->id_nazwisko) ? $ct->id_nazwisko : '', '{id_organ}' => (isset($ct) && $ct->id_organ) ? $ct->id_organ : '', '{id_adres}' => (isset($ct) && $ct->id_adres) ? $ct->id_adres : '', '{id_poczta}' => (isset($ct) && $ct->id_poczta) ? $ct->id_poczta : '', '{id_miasto}' => (isset($ct) && $ct->id_miasto) ? $ct->id_miasto : '', '{id_telefon}' => (isset($ct) && $ct->id_telefon) ? $ct->id_telefon : '', ); CustomerThread.php <?php class CustomerThread extends CustomerThreadCore { public $id_imie; public $id_nazwisko; public $id_organ; public $id_adres; public $id_poczta; public $id_miasto; public $id_telefon; 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), 'id_imie' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 50, 'required' => true), 'id_nazwisko' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 50, 'required' => true), 'id_organ' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255, 'required' => true), 'id_adres' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 255, 'required' => true), 'id_poczta' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 15, 'required' => true), 'id_miasto' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 30, 'required' => true), 'id_telefon' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 15, 'required' => true), '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'), ), ); } and message.tpl {if !$email} <dl class="dl-horizontal"><dt>{l s='id_imie:'}</dt> <dd>{$message.id_imie}</dd> </dl> <dl class="dl-horizontal"> <dt>{l s='id_nazwisko:'}</dt> <dd>{$message.id_nazwisko}</dd> </dl> <dl class="dl-horizontal"> <dt>{l s='id_organ:'}</dt> <dd>{$message.id_organ}</dd> </dl> <dl class="dl-horizontal"> <dt>{l s='id_adres:'}</dt> <dd>{$message.id_adres}</dd> </dl> <dl class="dl-horizontal"> <dt>{l s='id_poczta:'}</dt> <dd>{$message.id_poczta}</dd> </dl> <dl class="dl-horizontal"> <dt>{l s='id_miasto:'}</dt> <dd>{$message.id_miasto}</dd> </dl> <dl class="dl-horizontal"> <dt>{l s='id_telefon:'}</dt> <dd>{$message.id_telefon}</dd> </dl> <dl class="dl-horizontal"> <dt>{l s='Thread ID:'}</dt> <dd>{$message.id_customer_thread}</dd> </dl> <dl class="dl-horizontal"> <dt>{l s='Message ID:'}</dt> <dd>{$message.id_customer_message}</dd> </dl> {/if} And in phpmyadmin : Edited September 23, 2014 by pbpo (see edit history) Link to comment Share on other sites More sharing options...
pbpo Posted September 23, 2014 Share Posted September 23, 2014 I do not know why, but when the (id_imie / id_nazwisko etc) on extrafield all began work correctly .... Can someone explain this to me? Link to comment Share on other sites More sharing options...
tatamimi Posted September 24, 2014 Share Posted September 24, 2014 (edited) I don't know how it works but I don't use message.tpl (and I can't find that file in my template folder...).I use the file of "contact-form.html" in my mail folder ( /themes/yourtheme/mails/yourlang/contact-form.html ) to send mail by contact form page. Edited September 24, 2014 by tatamimi (see edit history) Link to comment Share on other sites More sharing options...
pbpo Posted September 24, 2014 Share Posted September 24, 2014 That so let me quote:http://nemops.com/adding-new-fields-to-prestashop-contact-form/#.VCJV-_l_t5P"Now, as a really last step, we will add the field to the back office as well. Again, following the maintainability principle, we will not directly modify the core files, but use overrides. Go to your admin folder, then themes\default\template\controllers\customer_threads, and copy message.tpl." Link to comment Share on other sites More sharing options...
Ivan Leon Posted October 17, 2014 Share Posted October 17, 2014 Hi Nemo, How can I add country, and the state as a drop down list field? It's really important for my business to know the location of my customers. how should I link the database fields ps_country, ps_country_lang or ps_state? Thanks Link to comment Share on other sites More sharing options...
namelesshachi Posted December 22, 2014 Share Posted December 22, 2014 This tutorial is really good! i've used it before. But now i tried to use it in Prestashop 1.6 The first field worked, is sent and everything But when i try to add another extrafield, is not being sent. Any advice on this? Link to comment Share on other sites More sharing options...
Godswar Posted March 24, 2015 Share Posted March 24, 2015 Hi can someone please help me with this part i am not sure how to do this or where ??? The field is there, but our database doesn’t know. Let’s tell it! Login to the database using your favorite tool (my choice is always phpMyAdmin).Locate the ps_customer_thread table (as always, your prefix might be other than ps_). Add a new TEXT column with no limitations. Again, if you chose something other than a text input, like a radio or checkbox, you might want to use TINYINT instead, to add only 1 or 0. Link to comment Share on other sites More sharing options...
pbraconnot Posted May 25, 2015 Share Posted May 25, 2015 (edited) Very nice module! I have just one question from one of my clients. How can I prove to him that you guys are not logging, tracking all the messages? There are server side calls from JS in this code so all the user information should be passive of being logged. Edited May 25, 2015 by pbraconnot (see edit history) Link to comment Share on other sites More sharing options...
Khundo Posted June 28, 2015 Share Posted June 28, 2015 (edited) Hi Nemo,Thank you for your tutorialI managed to put half the name and phone contact-form for the 1.4.11 version of PrestaShoptesting there send two messages:- The first message via email to the seller, there has name, phone, email and message displays but no id_order or id_product- 2nd message via email to the customer advising that his message has been sent, there has id.order, id.product, email and messages but not names or phoneIs it possible to bring together in one so the seller and customer can receive the same message?eg:Name: Nemophone nuber : 06xxmail: [email protected]id_order: xxl12id_product: bronzageMessage: received the purchased tanning productThank you in advance Edited June 28, 2015 by Khundo (see edit history) Link to comment Share on other sites More sharing options...
rramos-acuabit Posted October 3, 2015 Share Posted October 3, 2015 (edited) Hello. I'm using 1.6.0.11 version, but in var_dump() say me "Undefined index "telefono". ¿There is some issue with this version and overrides? PD: I always edit my table ps_customer_thread override/clasess/CustomerThread.php <?php class CustomerThread extends CustomerThreadCore { public $telefono; 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), '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'), 'telefono' => array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 15, 'required' => true), ), ); } (in my theme folder) contact-form.tpl <p class="form-group"> <label for="telefono">{l s='Teléfono'}<sup>*</sup></label> {if isset($customerThread.telefono)} <input class="form-control" type="text" id="telefono" name="telefono" value="{$customerThread.telefono|escape:'htmlall':'UTF-8'}" readonly="readonly" /> {else} <input class="form-control validate" type="text" id="telefono" name="telefono" data-validate="isPhoneNumber" value="{$smarty.post.telefono|escape:'htmlall':'UTF-8'}" /> {/if} </p> override/controllers/front/ContactController.php <?php class ContactController extends ContactControllerCore { public function postProcess() { if (Tools::isSubmit('submitMessage')) { $fileAttachment = null; if (isset($_FILES['fileUpload']['name']) && !empty($_FILES['fileUpload']['name']) && !empty($_FILES['fileUpload']['tmp_name'])) { $extension = array('.txt', '.rtf', '.doc', '.docx', '.pdf', '.zip', '.png', '.jpeg', '.gif', '.jpg'); $filename = uniqid().substr($_FILES['fileUpload']['name'], -5); $fileAttachment['content'] = file_get_contents($_FILES['fileUpload']['tmp_name']); $fileAttachment['name'] = $_FILES['fileUpload']['name']; $fileAttachment['mime'] = $_FILES['fileUpload']['type']; } $message = Tools::getValue('message'); // Html entities is not usefull, iscleanHtml check there is no bad html tags. if (!($from = trim(Tools::getValue('from'))) || !Validate::isEmail($from)) $this->errors[] = Tools::displayError('Invalid email address.'); else if (!$message) $this->errors[] = Tools::displayError('The message cannot be blank.'); else if (!Validate::isCleanHtml($message)) $this->errors[] = Tools::displayError('Invalid message'); else if (!($id_contact = (int)(Tools::getValue('id_contact'))) || !(Validate::isLoadedObject($contact = new Contact($id_contact, $this->context->language->id)))) $this->errors[] = Tools::displayError('Please select a subject from the list provided. '); else if (!empty($_FILES['fileUpload']['name']) && $_FILES['fileUpload']['error'] != 0) $this->errors[] = Tools::displayError('An error occurred during the file-upload process.'); else if (!empty($_FILES['fileUpload']['name']) && !in_array(substr($_FILES['fileUpload']['name'], -4), $extension) && !in_array(substr($_FILES['fileUpload']['name'], -5), $extension)) $this->errors[] = Tools::displayError('Bad file extension'); else { $customer = $this->context->customer; if (!$customer->id) $customer->getByEmail($from); $contact = new Contact($id_contact, $this->context->language->id); if (!(( ($id_customer_thread = (int)Tools::getValue('id_customer_thread')) && (int)Db::getInstance()->getValue(' SELECT cm.id_customer_thread FROM '._DB_PREFIX_.'customer_thread cm WHERE cm.id_customer_thread = '.(int)$id_customer_thread.' AND cm.id_shop = '.(int)$this->context->shop->id.' AND token = \''.pSQL(Tools::getValue('token')).'\'') ) || ( $id_customer_thread = CustomerThread::getIdCustomerThreadByEmailAndIdOrder($from, (int)Tools::getValue('id_order')) ))) { $fields = Db::getInstance()->executeS(' SELECT cm.id_customer_thread, cm.id_contact, cm.id_customer, cm.id_order, cm.id_product, cm.email FROM '._DB_PREFIX_.'customer_thread cm WHERE email = \''.pSQL($from).'\' AND cm.id_shop = '.(int)$this->context->shop->id.' AND ('. ($customer->id ? 'id_customer = '.(int)($customer->id).' OR ' : '').' id_order = '.(int)(Tools::getValue('id_order')).')'); $score = 0; foreach ($fields as $key => $row) { $tmp = 0; if ((int)$row['id_customer'] && $row['id_customer'] != $customer->id && $row['email'] != $from) continue; if ($row['id_order'] != 0 && Tools::getValue('id_order') != $row['id_order']) continue; if ($row['email'] == $from) $tmp += 4; if ($row['id_contact'] == $id_contact) $tmp++; if (Tools::getValue('id_product') != 0 && $row['id_product'] == Tools::getValue('id_product')) $tmp += 2; if ($tmp >= 5 && $tmp >= $score) { $score = $tmp; $id_customer_thread = $row['id_customer_thread']; } } } $old_message = Db::getInstance()->getValue(' SELECT cm.message FROM '._DB_PREFIX_.'customer_message cm LEFT JOIN '._DB_PREFIX_.'customer_thread cc on (cm.id_customer_thread = cc.id_customer_thread) WHERE cc.id_customer_thread = '.(int)($id_customer_thread).' AND cc.id_shop = '.(int)$this->context->shop->id.' ORDER BY cm.date_add DESC'); if ($old_message == $message) { $this->context->smarty->assign('alreadySent', 1); $contact->email = ''; $contact->customer_service = 0; } 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); if ($id_order = (int)Tools::getValue('id_order')) $ct->id_order = $id_order; if ($id_product = (int)Tools::getValue('id_product')) $ct->id_product = $id_product; $ct->telefono = Tools::getValue('telefono'); $ct->update(); } else { $ct = new CustomerThread(); if (isset($customer->id)) $ct->id_customer = (int)($customer->id); $ct->id_shop = (int)$this->context->shop->id; if ($id_order = (int)Tools::getValue('id_order')) $ct->id_order = $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; $ct->status = 'open'; $ct->token = Tools::passwdGen(12); $ct->telefono = Tools::getValue('telefono'); $ct->add(); } if ($ct->id) { $cm = new CustomerMessage(); $cm->id_customer_thread = $ct->id; $cm->message = Tools::htmlentitiesUTF8($message); if (isset($filename) && rename($_FILES['fileUpload']['tmp_name'], _PS_MODULE_DIR_.'../upload/'.$filename)) $cm->file_name = $filename; $cm->ip_address = ip2long($_SERVER['REMOTE_ADDR']); $cm->user_agent = $_SERVER['HTTP_USER_AGENT']; if (!$cm->add()) $this->errors[] = Tools::displayError('An error occurred while sending the message.'); } else $this->errors[] = Tools::displayError('An error occurred while sending the message.'); } if (!count($this->errors)) { $var_list = array( '{order_name}' => '-', '{attached_file}' => '-', '{message}' => Tools::nl2br(stripslashes($message)), '{email}' => $from, '{telefono}' => (isset($ct) && $ct->telefono) ? $ct->telefono : '' ); if (isset($filename)) $var_list['{attached_file}'] = $_FILES['fileUpload']['name']; $id_order = (int)Tools::getValue('id_order'); if (isset($ct) && Validate::isLoadedObject($ct)) { if ($ct->id_order) $id_order = $ct->id_order; $subject = sprintf(Mail::l('Your message has been correctly sent #ct%1$s #tc%2$s'), $ct->id, $ct->token); } else $subject = Mail::l('Your message has been correctly sent'); if ($id_order) { $order = new Order((int)$id_order); $var_list['{order_name}'] = $order->getUniqReference(); $var_list['{id_order}'] = $id_order; } if (empty($contact->email)) Mail::Send($this->context->language->id, 'contact_form', $subject, $var_list, $from, null, null, null, $fileAttachment); else { if (!Mail::Send($this->context->language->id, 'contact', Mail::l('Message from contact form').' [no_sync]', $var_list, $contact->email, $contact->name, $from, ($customer->id ? $customer->firstname.' '.$customer->lastname : ''), $fileAttachment) || !Mail::Send($this->context->language->id, 'contact_form', $subject, $var_list, $from, null, $contact->email, $contact->name, $fileAttachment)) $this->errors[] = Tools::displayError('An error occurred while sending the message.'); } } if (count($this->errors) > 1) array_unique($this->errors); else $this->context->smarty->assign('confirmation', 1); } } } } ¿Can you help me? Thanks. Edited October 3, 2015 by rramos-acuabit (see edit history) Link to comment Share on other sites More sharing options...
magix01 Posted October 29, 2015 Share Posted October 29, 2015 Does this guide apply to presta 1.6? Link to comment Share on other sites More sharing options...
pbpo Posted October 30, 2015 Share Posted October 30, 2015 (edited) Does this guide apply to presta 1.6? In 1.6.0.9 tested - work perfect In 1.6.0.11 not tested but I will try to do this. EDIT: In 1.6.0.11 not work... Have to wait for check it by Nemo. In lastest version Prestashop messages are sending correct, but in received mails new fields are empty. No errors in debug mode Edited October 30, 2015 by pbpo (see edit history) Link to comment Share on other sites More sharing options...
magix01 Posted October 30, 2015 Share Posted October 30, 2015 (edited) I have presta 1.6.1.1 And field in database is not populated, it was an upgrade from 1.5.4 presta (it worked) I re-did the entire procedure and its not working. EDIT: I have managed to make it submit info in the database, but the problem now is that it won't show in backend, i made the override and even edited core file message.tpl there are no changes, even when you empty the file it is still the same... I have disabled cache and it is on force compilation. I can't seem to find what's causing this? Regards Edited October 30, 2015 by magix01 (see edit history) Link to comment Share on other sites More sharing options...
babyewok Posted November 19, 2015 Share Posted November 19, 2015 (edited) OK, so I managed to get this working great on 1.6.1.1 (overriding controllers/admin/templates/customer_threads/helpers/view/views.tpl instead of message.tpl in the tutorual - an I had to copy in the otehr files in the views folder too for it to work). Anyway, then I went to test out my newly installed PayPal Europe module (the free, official one) and found that there was a conflict. The PayPal payment would go through, order would go through back office but I woudl get a blank page on returning to the shop after paying instead if seeing the confirmation page. The url was ... modules\paypal\express_checkout\payment.php (although not usin express checkout??) and the error included: Fatal error: Uncaught exception 'PrestaShopException' with message 'Property CustomerThread->extrafield is empty' in ......\classes\ObjectModel.php:909nStack trace:n#0 I have had to disable the extra fields to get PayPal to work. What is causing the issue as PayPal should have nothing to do with the Customer Thread? How can I get the two working together? There are actually two extra fields on the contact page, but the extrafield flagged up in the error is a required field Edited November 19, 2015 by babyewok (see edit history) Link to comment Share on other sites More sharing options...
vikasmnl Posted February 4, 2016 Share Posted February 4, 2016 Hi, I am using prestashop 1.6.1.3, and want to create a duplicate page of Contact- us. Requirement is to add new fileds such as checkboxes and radio buttons. Kindly help me somebody in the same... Thanks. Link to comment Share on other sites More sharing options...
FanieLumia Posted May 13, 2017 Share Posted May 13, 2017 (edited) Hey guys, First off, great tutorial! Thanks NemoPS!! But I see this was written quite some time ago, has someone not gone and developed a module or something that can make editing the contact form easier since then? And I dont know if something is wrong with my contact form, but it's really strange to me that the customer cannot type in his name in the form or that the form does not send the customer name inside the email. How is someone supposed to know who they are replying to if all the form is supplying is the email address and order number? It just seem like something really basic which should be included by default. Am I missing something? Edited May 13, 2017 by FanieLumia (see edit history) 1 Link to comment Share on other sites More sharing options...
ciolo18 Posted May 21, 2018 Share Posted May 21, 2018 Hi, I want to add a mandatory checkbox in Contact form to throw an error message when the checkbox is not checked , I followed the steps from tutorial, but the error doesn't appear, something I did wrong. Please help, This is the code inserted in contact-form.tpl <h3 class="page-subheading"> Confidențialitate date client</h3><div style="width:21px; float:left;"><div class="required checkbox"> <div class="checker" id="uniform-customer_privacy"> <span class="checkbox"> <label for="ps_customer_checkbox">{l s=''}</label> {if isset($customerThread.ps_customer_checkbox)} <input type="checkbox" id="ps_customer_checkbox" name="ps_customer_checkbox" value="{$customerThread.ps_customer_checkbox|escape:'htmlall':'UTF-8'}" readonly="readonly" /> {else} <input type="checkbox" value="1" id="ps_customer_checkbox" name="ps_customer_checkbox" autocomplete="off"> {/if} </span> </div></div></div><div style="width: 92%; float: left; margin-top: 8px;"> <label for="customer_priv" style="font-weight: normal;"><!--? xml version="1.0" encoding="UTF-8" ?--><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> Datele personale oferite de dumneavoastră sunt confidentiale *</label></div> The CustomerTheard,php: <?php class CustomerThread extends CustomerThreadCore { public $ps_customer_checkbox; 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), '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'), 'ps_customer_checkbox' => array('type' => self::TYPE_BOOL, 'validate' =>'isBool', 'required' => true), ), ); } The code from ContactController from override/controllers/front/ContactController.php 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->ps_customer_checkbox = (int)Tools::getValue('ps_customer_checkbox'); $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; $ct->status = 'open'; $ct->token = Tools::passwdGen(12); $ct->ps_customer_checkbox = (int)Tools::getValue('ps_customer_checkbox') $ct->add(); } if ($ct->ps_customer_checkbox = 0){ $this->errors[] = Tools::displayError('Arunca-mi eroare'); The db is populated when the checkbox is unchecked, but no error is thrown. Thanks in advance, Cristi Link to comment Share on other sites More sharing options...
christian_at_joseph Posted September 10, 2018 Share Posted September 10, 2018 I wondered if the solution of nemo still works in 1.7 (tested in 1.7.3.4) and it kinda does, just the files are at different positions, called differently, I tried the following thing to add a field (and remember this solution is not update proof and the additional fields are not safed in the backoffice): Update contact.html + contact.txt in the theme/mails folder: <span style="color:#333"><strong>Name: {contactname}</strong></span><br /><br /> Add the contactname line to the $var_list array in the file contactform.php located in the modules/contactform folder: $var_list = [ '{order_name}' => '-', '{attached_file}' => '-', '{message}' => Tools::nl2br(stripslashes($message)), '{email}' => $from, '{product_name}' => '', '{contactname}' => Tools::nl2br(stripslashes($contactname)), ]; Add a line to the beginning of the function sendMessage(){ in the same file (contactform.php) $contactname = trim(Tools::getValue('contactname')); Add the following lines to the <section class="form-fields"> part in the file contactform.tpl located in the theme/modules/contactform/views/template/widget folder: <div class="form-group row"> <label class="col-md-3 form-control-label">{l s='Name' d='Shop.Forms.Labels'}</label> <div class="col-md-6"> <input class="form-control" name="contactname" type="text" value="{$contact.contactname}" placeholder="{l s='Ihr Name' d='Shop.Forms.Help'}" > </div> </div> I know it's ugly, but hey, it's a start 1 Link to comment Share on other sites More sharing options...
babyewok Posted August 1, 2019 Share Posted August 1, 2019 On 9/10/2018 at 3:11 PM, christian_at_joseph said: I wondered if the solution of nemo still works in 1.7 (tested in 1.7.3.4) and it kinda does, just the files are at different positions, called differently, I tried the following thing to add a field (and remember this solution is not update proof and the additional fields are not safed in the backoffice): Update contact.html + contact.txt in the theme/mails folder: <span style="color:#333"><strong>Name: {contactname}</strong></span><br /><br /> Add the contactname line to the $var_list array in the file contactform.php located in the modules/contactform folder: $var_list = [ '{order_name}' => '-', '{attached_file}' => '-', '{message}' => Tools::nl2br(stripslashes($message)), '{email}' => $from, '{product_name}' => '', '{contactname}' => Tools::nl2br(stripslashes($contactname)), ]; Add a line to the beginning of the function sendMessage(){ in the same file (contactform.php) $contactname = trim(Tools::getValue('contactname')); Add the following lines to the <section class="form-fields"> part in the file contactform.tpl located in the theme/modules/contactform/views/template/widget folder: <div class="form-group row"> <label class="col-md-3 form-control-label">{l s='Name' d='Shop.Forms.Labels'}</label> <div class="col-md-6"> <input class="form-control" name="contactname" type="text" value="{$contact.contactname}" placeholder="{l s='Ihr Name' d='Shop.Forms.Help'}" > </div> </div> I know it's ugly, but hey, it's a start I used this workaround for PS 1.7.6 and all seems to work well except that when in debug mode, I get: Notice: Undefined index: contactname - any idea why that is? Link to comment Share on other sites More sharing options...
Shara_AC Posted November 14, 2019 Share Posted November 14, 2019 Hello mr. I'am sorry because my english is bad I'am adding field image from formatter class. how to add attribute accept="image/*" in formField class please help me and thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now