Jump to content

Add some fields into Contact Form in prestashop 1.4.4.1


Recommended Posts

  • 1 month later...

I have successfully added a name field to the contact form in PrestaShop 1.4.4.0. I edited these files:

----controllers\contactcontoller.php (this should go in the override\controllers folder when complete)

----mails\en\contact.txt

----mails\en\contact.html

----themes\yourtheme\contact-form.tpl

 

contact-form.tpl

<p class="text">
 <label for="name">{l s='Name'}</label>
 {if isset($customerThread.name)}
<input type="text" id="name" name="fromname" value="{$customerThread.name}" readonly="readonly" />
 {else}
<input type="text" id="name" name="fromname" value="{$name}" />
 {/if}
</p>

 

contactcontroller.php

Line 82: (validate Name field is filled in)

if (!($fromname = trim(Tools::getValue('fromname'))) OR (!($fromname = nl2br2($fromname))))
$this->errors[] = Tools::displayError('Contact Name cannot be blank');
elseif (!($from = trim(Tools::getValue('from'))) OR !Validate::isEmail($from))
$this->errors[] = Tools::displayError('Invalid e-mail address');

 

Line 156 (orig) (send fromName as array parm and as name in Mail header)

if (Mail::Send((int)(self::$cookie->id_lang), 'contact', Mail::l('Message from contact form'), array('{email}' => $from, '{message}' => stripslashes($message),'{fromName}' => stripslashes($fromname)), $contact->email, $contact->name, $from, ((int)(self::$cookie->id_customer) ? $customer->firstname.' '.$customer->lastname : $fromname), $fileAttachment)

 

Line 208 (orig)

if (Mail::Send((int)(self::$cookie->id_lang), 'contact', Mail::l('Message from contact form'), array('{email}' => $from, '{message}' => stripslashes($message),'{fromName}' => stripslashes($fromname)), $contact->email, $contact->name, $from, ((int)(self::$cookie->id_customer) ? $customer->firstname.' '.$customer->lastname : $fromname), $fileAttachment)

 

contact.html

Line 18

<TR>
<TD align=left>Name: <STRONG>{fromName}</STRONG> <BR></TD></TR>

 

contact.txt (added at Line 5)

Name: {fromName}

 

I hope this helps someone else.

  • Like 2

Share this post


Link to post
Share on other sites

Many thanks for the information it works great, just two questions, If I upload the controllers\contactcontoller.php to the override\controllers folder I get a blank screen. If I keep in the original folder works fine, also

 

Line 208 (orig)

if (Mail::Send((int)(self::$cookie->id_lang), 'contact', Mail::l('Message from contact form'), array('{email}' => $from, '{message}' => stripslashes($message),'{fromName}' => stripslashes($fromname)), $contact->email, $contact->name, $from, ((int)(self::$cookie->id_customer) ? $customer->firstname.' '.$customer->lastname : $fromname), $fileAttachment)

 

have tried adding that and it doesnt work, but it works without, not sure if I should replace

 

the } , put the code before, after or other, have tried a few alternatives but none seem to work, however the form seems to works well without either of those steps .

 

Cheers

 

For posting the form changes.

  • Like 1

Share this post


Link to post
Share on other sites

Same here.

 

Works only ignoring the changes for line 208 from clearvuecyclones post.

 

By other side, following the logic of the changes to create a "name" field, i'm trying to create a "state" and "company" fields in the form but i'm doing something wrong 'cause apache log says a "parse error" in line 172. I post my code here, may anyone can help. Thank you.

 

if (!($fromname = trim(Tools::getValue('fromname'))) OR (!($fromname = nl2br2($fromname))))
$this->errors[] = Tools::displayError('El campo Nombre no puede estar en blanco');
if (!($empresa = trim(Tools::getValue('empresa'))) OR (!($empresa = nl2br2($empresa))))
$this->errors[] = Tools::displayError('El campo Empresa no puede estar en blanco');
if (!($provincia = trim(Tools::getValue('provincia'))) OR (!($provincia = nl2br2($provincia))))
$this->errors[] = Tools::displayError('El campo Provincia no puede estar en blanco');
elseif (!($from = trim(Tools::getValue('from'))) OR !Validate::isEmail($from))
$this->errors[] = Tools::displayError('Invalid e-mail address');

 

if (Mail::Send((int)(self::$cookie->id_lang), 'contact', Mail::l('Message from contact form'), array('{email}' => $from, '{message}' => stripslashes($message),'{fromName}' => stripslashes($fromname)),'{empresa}' => stripslashes($empresa)),'{provincia}' => stripslashes($provincia)), $contact->email, $contact->name, $from, ((int)(self::$cookie->id_customer) ? $customer->firstname.' '.$customer->lastname : $fromname), $fileAttachment)
  AND Mail::Send((int)(self::$cookie->id_lang), 'contact_form', Mail::l('Your message has been correctly sent'), array('{message}' => stripslashes($message)), $from))
  self::$smarty->assign('confirmation', 1);

  • Like 1

Share this post


Link to post
Share on other sites

Ok, now it's working. The second code was wrong (the parenthesis), the right one:

 

if (Mail::Send((int)(self::$cookie->id_lang), 'contact', Mail::l('Message from contact form'), array('{email}' => $from, '{message}' => stripslashes($message),'{fromName}' => stripslashes($fromname), '{empresa}' => stripslashes($empresa), '{provincia}' => stripslashes($provincia)), $contact->email, $contact->name, $from, ((int)(self::$cookie->id_customer) ? $customer->firstname.' '.$customer->lastname : $fromname), $fileAttachment)

Share this post


Link to post
Share on other sites
  • 2 weeks later...
  • 2 weeks later...

I'm trying to edit my contact form too. I'm very frustrated.

I tried the code that Clearvuecyclones posted except for the line 208 bit and I put the controllers file back in the same directory.

 

The name field shows up and it does validate it but it doesn't automatically pull the name from the database and when it's filled in manually it doesn't show up on the generated email message.

 

I'm about to give up with this and try another shopping cart solution.

Share this post


Link to post
Share on other sites
  • 2 months later...

Thank you but i have a little problem. I added two fields (FirstName and LastName)

 

Contact Form working = YES

Mail Sent with firstname and lastname = YES

 

but... if i login to the site, firstname and lastname fields aren't filled with my values. (in contrary with the email)

 

I put value="{$customer.firstname}"

and value="{$firstname}" but nothing happens

Share this post


Link to post
Share on other sites
  • 2 months later...

Thank you for the post.

How I can to added two fileds if I want that this fields aren´t obligatory?

With your code all it´s ok if the user complete all fields, but I wnat two fields no obligatory and I don´t know how to put it.

I think don´t write the code in the line82 of PHP, but in this case don´t send the fields in the mail.

Can you help me? Thank you, and sorry for my English.

Share this post


Link to post
Share on other sites
  • 7 months later...
  • 3 weeks later...
  • 11 months later...
Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More