Jump to content

Add two fields to PS contact form?


midana

Recommended Posts

I have tried a guide of doing this previously but it didn't work. Think the cause could have been that it was dated.

 

Does anyone know good links or information of how to add functioning fields to the Prestashop contact form?

 

Would like to add a field for name and phone number to it.

Link to comment
Share on other sites

Here is a tutorial on just that I have used for years, if you follow exactly should be no problem.

 

First edit ..themes/yourtheme/contact-form.tpl
 
 add below just above:    <p class="text"> <label for ="email">
 
      <p class="text">
         <label for="contactperson">{l s='Name'}</label>
         <input type="text" id="contactperson" name="contactperson" value="{if isset($contactperson)}{$contactperson|escape:'htmlall':'UTF-8'|stripslashes}{/if}" />
     </p>
     <p class="text">
         <label for="phonenumber">{l s='Phone Number'}</label>
         <input type="text" id="phonenumber" name="phonenumber" value="{if isset($phonenumber)}{$phonenumber|escape:'htmlall':'UTF-8'|stripslashes}{/if}" />
     </p>
 
 
 
 Now edit ContactController.php
 
In 1.4 controllers/ContactController.php
in 1.5 controllers/front/ContactController.php
 
Add below just after:     $this->errors[] = Tools::displayError('Bad file extension');
 
elseif (!empty($_FILES['fileUpload']['name']) AND !in_array(substr($_FILES['fileUpload']['name'], -4), $extension) AND !in_array(substr($_FILES['fileUpload']['name'], -5), $extension))
                $this->errors[] = Tools::displayError('Bad file extension');
                elseif (!($contactperson = nl2br2(Tools::getValue('contactperson'))))
                $this->errors[] = Tools::displayError('Name cannot be blank');
                elseif (!($phonenumber = nl2br2(Tools::getValue('phonenumber'))))
                $this->errors[] = Tools::displayError('Phone Number cannot be blank');
 
       else
{
    
 
 
 
 Then change the following:
  
  change this:
  
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', ((isset($ct) && Validate::isLoadedObject($ct)) ? sprintf(Mail::l('Your message has been correctly sent #ct%1$s #tc%2$s'), $ct->id, $ct->token) : Mail::l('Your message has been correctly sent')), $var_list, $from, null, $contact->email, $contact->name, $fileAttachment))
$this->errors[] = Tools::displayError('An error occurred while sending the message.');
 
  
  
  
  To this:
  
  if (Mail::Send((int)(self::$cookie->id_lang), 'contact', Mail::l('Message from contact form'), array('{email}' => $from, '{message}' => stripslashes($message), '{contactperson}' => stripslashes ( $contactperson ),'{phonenumber}' => stripslashes ( $phonenumber )), $contact->email, $contact->name, $from, ((int)(self::$cookie->id_customer) ? $customer->firstname.' '.$customer->lastname : ''), $fileAttachment)
              AND Mail::Send((int)(self::$cookie->id_lang), 'contact_form', Mail::l('Your message has been correctly sent'), array('{email}' => $from, '{message}' => stripslashes($message), '{contactperson}' => stripslashes ( $contactperson ),'{phonenumber}' => stripslashes ( $phonenumber )), $from))
              self::$smarty->assign('confirmation', 1);
       else
$this->errors[] = Tools::displayError('An error occurred while sending message.');
 
 
 
      Change this: (For 1.4xx only)
 
if (empty($contact->email))
 Mail::Send((int)self::$cookie->id_lang, 'contact_form', Mail::l('Your message has been correctly sent', (int)self::$cookie->id_lang), array('{message}' => stripslashes($message)), $from);
self::$smarty->assign('confirmation', 1);
  
  
  To this:
  
if (empty($contact->email))
         Mail::Send((int)(self::$cookie->id_lang), 'contact_form', Mail::l('Your message has been correctly sent'), array('{message}' => stripslashes($message),'{contactperson}' => stripslashes ( $contactperson ),'{phonenumber}' => stripslashes ( $phonenumber )), $from);
             self::$smarty->assign('confirmation', 1);
 
 
 
 
Last we need to add the fileds to the contact.html mail, (mails/en/contact.html & contact.txt)
 
to contact.html
<tr>
<td align="left">Name: {contactperson} <br><br> Phone Number: {phonenumber}</td>
</tr>
 
to contact.txt
 
Name: {contactperson}
 
Phone #: {phonenumber}
 
 
 
 
Here is a pic of my 1.5 test site:
 
post-310220-0-32635300-1386863047_thumb.jpg
Edited by tdr170 (see edit history)
  • Like 2
Link to comment
Share on other sites

I don't find this one in my contactcontroller: 

 

  if (Mail::Send((int)self::$cookie->id_lang, 'contact', Mail::l('Message from contact form', (int)self::$cookie->id_lang), array('{email}' => $from, '{message}' => stripslashes($message)), $contact->email, $contact->name, $from, ((int)(self::$cookie->id_customer) ? $customer->firstname.' '.$customer->lastname : ''), $fileAttachment)
AND Mail::Send((int)self::$cookie->id_lang, 'contact_form', Mail::l('Your message has been correctly sent', (int)self::$cookie->id_lang), array('{message}' => stripslashes($message)), $from))
self::$smarty->assign('confirmation', 1);
else
$this->errors[] = Tools::displayError('An error occurred while sending message.');

 

 

I have this, what should I add to it and where? (if I copied the right text)

 

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', ((isset($ct) && Validate::isLoadedObject($ct)) ? sprintf(Mail::l('Your message has been correctly sent #ct%1$s #tc%2$s'), $ct->id, $ct->token) : Mail::l('Your message has been correctly sent')), $var_list, $from, null, $contact->email, $contact->name, $fileAttachment))
$this->errors[] = Tools::displayError('An error occurred while sending the message.');
}
}

 

 

 

Thank you so much for helping me.

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...
Guest presta06

Hi

I want also to have two more fields in contact form, sending email is working, but i want to see it in backoffice also.

I added in AdminCustomerThreadsController.php

'contactperson' => array(
                'title' => $this->l('Contact Person'),
                'width' => 100,
                'filter_key' => 'contactperson',
                'tmpTableFilter' => true,
            ),
            'phonenumber' => array(
                'title' => $this->l('Phone number'),
                'width' => 100,
                'filter_key' => 'phonenumber',
                'tmpTableFilter' => true,
            ),

In table customer_message I added two fields phonenumber and contactperson.

 

Now I can get information from database, but i dont know what to do to insert into database new information from contact form.

Can anybody help?

Link to comment
Share on other sites

  • 3 months later...
  • 3 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...