Jump to content

[solved / Tutorial] Custom Contact page forms


Recommended Posts

I need help making a new custom form, i'm not a php programmer so i dont really know what to do, could any one help me?

 

I need:

 

Company name (required)

Contact person (required)

Email (required)

Contact phone (required)

Country (required)

 

Project description - multiline textbox (required)

 

File attachment - posibility for user to attach file (not required)

 

(using prestashop 1.4.4.1)

 

EDIT: See Tutorial Below

Link to comment
Share on other sites

i understand little bit, i edited the Contact.php under classes and the contact-form.tpl up to there i think is working fine as im not getting any error, the only place im having trouble is the mail, which i set it under {..} but im not getting anything

Link to comment
Share on other sites

I solved the issue, if anyone needs how to add more fields on 1.4.1 let me know.

 

I'd like to know please.

 

I have posted about this previously but never got any replies to it.

 

I have managed to include a field for mobile phone number but could never get it to show in the email.

 

Thanks

Link to comment
Share on other sites

  • 3 weeks later...

As mentioned before i'm not a php programmer but with hard work I figured my self as people on the forum that knows how to do it, couldn't be bothered explaining it for free.

 

This is for 1.4+ to work with your contact form that has attachment enabled.

 

I will show you the lines that I have added to my form, but you can change to the ones that you need by changing the values.

 

There are few files that has to be edited:

MAKE SURE TO MAKE A BACK UP OF ALL THESE FILES BEFORE EDITING THEM

/controllers/ContactController.php

/themes/your-theme/contact-form.tpl

/mails/en(or and other languages using)/contact.html

/mails/en(or and other languages using)/contact.txt

/mails/en(or and other languages using)/contact_form.html

/mails/en(or and other languages using)/contact_form.txt

 

 

 

/controllers/ContactController.php

Around the like 93 you will see:

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');
		else

 

After the line $this->errors[] = Tools::displayError('Bad file extension'); and before else make a space and add this code:

elseif (!($companyname = nl2br2(Tools::getValue('companyname'))))
	$errors[] = Tools::displayError('Comapny name cannot be blank');

and it should look like this with many others if you need:

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 (!($companyname = nl2br2(Tools::getValue('companyname'))))
	$errors[] = Tools::displayError('Comapny name cannot be blank');
	elseif (!($contactperson = nl2br2(Tools::getValue('contactperson'))))
	$errors[] = Tools::displayError('Contact Person cannot be blank');
	elseif (!($phonenumber = nl2br2(Tools::getValue('phonenumber'))))
	$errors[] = Tools::displayError('Phone Number cannot be blank');
	elseif (!($country = nl2br2(Tools::getValue('country'))))
	$errors[] = Tools::displayError('Country cannot be blank');

		else

Around the line 156 you have this code:

if (Mail::Send((int)(self::$cookie->id_lang), 'contact', Mail::l('Message from contact form'), 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'), array('{message}' => stripslashes($message)), $from))
					self::$smarty->assign('confirmation', 1);

and you have to add:

'{companyname}' => stripslashes ( $companyname ),

the result should look like this:

if (Mail::Send((int)(self::$cookie->id_lang), 'contact', Mail::l('Message from contact form'), array('{email}' => $from, '{message}' => stripslashes($message), '{companyname}' => stripslashes ( $companyname ), '{contactperson}' => stripslashes ( $contactperson ),'{phonenumber}' => stripslashes ( $phonenumber ), '{country}' => stripslashes ( $country )), $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), '{companyname}' => stripslashes ( $companyname ), '{contactperson}' => stripslashes ( $contactperson ),'{phonenumber}' => stripslashes ( $phonenumber ), '{country}' => stripslashes ( $country )), $from))
					self::$smarty->assign('confirmation', 1);

Then on the line 205 you have 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)), $from);
						self::$smarty->assign('confirmation', 1);

And you should add:

'{companyname}' => stripslashes ( $companyname ),

And should look like 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), '{companyname}' => stripslashes ( $companyname ), '{contactperson}' => stripslashes ( $contactperson ),'{phonenumber}' => stripslashes ( $phonenumber ), '{country}' => stripslashes ( $country )), $from);
						self::$smarty->assign('confirmation', 1);

 

This was the most complicated part.

Now comes the next file which is the contact-form.tpl

Find a place where you want to add the new forms on your page and add:

<p>
		<label for="companyname">{l s='Company Name'}</label>
		<input type="text" id="companyname" name="companyname" value="{if isset($companyname)}{$companyname|escape:'htmlall':'UTF-8'|stripslashes}{/if}" />
	</p>

then you make sure all the values match the values from the previous file, the complete forms should look like this:

<p>
		<label for="companyname">{l s='Company Name'}</label>
		<input type="text" id="companyname" name="companyname" value="{if isset($companyname)}{$companyname|escape:'htmlall':'UTF-8'|stripslashes}{/if}" />
	</p>
	<p>
		<label for="contactperson">{l s='Contact Person'}</label>
		<input type="text" id="contactperson" name="contactperson" value="{if isset($contactperson)}{$contactperson|escape:'htmlall':'UTF-8'|stripslashes}{/if}" />
	</p>
	<p>
		<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>
	<p>
		<label for="country">{l s='Country'}</label>
		<input type="text" id="country" name="country" value="{if isset($country)}{$country|escape:'htmlall':'UTF-8'|stripslashes}{/if}" />
	</p>

Now that file is done, the next files are the mail files which you will be able to receive and the customer also receive the mail.

For the TXT files you add:

Company name: {companyname}

Contact person: {contactperson}

Phone number: {phonenumber}

Country: {country}

and for the HTML files you add:

Company name: {companyname}
			<br><br>
			Contact Person: {contactperson}
			<br><br>
			Phone Number: {phonenumber}
			<br><br>
			Country: {country}
			<br><br>

 

And next step is to test it out. if you follow and make sure all the values match for all the files, then it will work without any problem.

I hope it helps

  • Like 8
Link to comment
Share on other sites

  • 2 weeks later...

Hi Dmcwebd

 

Many thanks for your modification. It was easy to work through and works very well. In my case I just wanted to add the Phone Number to the form.

 

Just to point out one thing, when filling the form and leaving the Phone Number field blank the error message: There is 1 error :Mobile Number cannot be blank wasn't showing.

 

I had to change the first part of the code in the ContactController.php from:

 

elseif (!($phonenumber = nl2br2(Tools::getValue('phonenumber'))))
$errors[] = Tools::displayError('Phone Number cannot be blank');

to

 

elseif (!($phonenumber = nl2br2(Tools::getValue('phonenumber'))))
$this->errors[] = Tools::displayError('Phone Number cannot be blank');

 

It now correctly shows the error if the field is not filled.

 

Thanks once again for this modification.

Link to comment
Share on other sites

I can't get this to work either.

I seem to be cursed with this contact form.

 

I've followed the instructions verbatim and also from DaveL who found the error.

 

I still get error 500.

I've had enough.

 

Thanks for posting though, dmcwebd.

 

 

Are you trying to implement all of the field additions or just the phone number.

 

If just the phone number I can PM you the ContactController.php and contact-form.tpl files if you'd like.

 

Edit:

 

Actually I'll add them here in case anyone else would like to use them

 

Just remame the old file first so that you can revert back if it doesn't work for you.

 

Don't forget to force compile to get the changes to the .tpl file to implement.

contact-form and controller.zip

Link to comment
Share on other sites

 

 

Are you trying to implement all of the field additions or just the phone number.

 

If just the phone number I can PM you the ContactController.php and contact-form.tpl files if you'd like.

 

 

Thanks dave!

I started out just doing the "company name" field from the tutorial.

The tpl file was not where I ran into problems it's with the controller. The slightest change made to the controller would give me 500 server error message. Earlier in the day yesterday, I was able to modify the controller to at least get the "required" errors to show up but not now.

 

All I am trying to do is add First name, last name and phone number.

I'm not even trying to pull the info from the DB. I'll be thrilled if I could just get it to work at all.

 

I will try your files shortly and let you know what happens.

 

By the way, did you try putting that slide captcha on your form? I'd still really like to do that but the module does not show up in my modules even though it's on the server.

Link to comment
Share on other sites

I was able to get your files to work properly, dave. Only thing is I didn't change the mail files yet. What did you add to those? And what did you edit these files in?

At first I tried to copy and paste the code and it didn't work then I just extract the files and uploaded them and didn't have any problems.

Link to comment
Share on other sites

Yes the controller is indeed the most difficult edit for this mod. All I could suggest is to do one field at a time and check to see if it works for you before moving on to the next.

 

Regarding the slide captcha, I have this installed on my test site on localhost. It works very well and looks good too.

 

Just check your install and make sure the module is placed correctly If it is in

/modules/slidecaptcha/slidecaptcha

it will not so up in the module list.

 

I have attached a copy of the mail files for you to have a look at. It's really just a a very short line of code. I also only did this on the contact.html and contact.txt. The contact-form.html and contact-form.txt are the forms sent to the customer. They already know their phone number so no need to send it back to them.

 

On contact.html on line #19 you can see the Mobile Phone line

 

 <tr>
  <td align="left">
E-mail address: <a href="mailto:{email}"><b>{email}</b></a>
<br><br>
Mobile Phone: {phonenumber}
<br><br>
Message: {message}
  </td>

 

The same lie of code applies to the contact.txt starting at line #5

 

E-mail address: {email}
Mobile Phone:  {phonenumber}
Message:
{message}

 

For editing files I use Notepad++ which is a free source code editor. You can download it HERE

Link to comment
Share on other sites

FINALLY!!!

Dave L saves the day!

:D

 

 

I couldn't have got it to work without your help.

 

I figured out what the problem is and where many others may be running into problems.

  • I used a number for one of the values ("1stname" instead of "firstname") It didn't like having a number in there.
  • In the lines of code in the controller around 156 and 208, you will notice there are parenthesis... For example '{firstname}' => stripslashes ( $firstname ), '{lastname}' => stripslashes ( $lastname )), $from))

​.... OK only the last one gets two parenthesis like closing an html tag. All the others before it have one. If you put two on those it won't work. If you put one on the end it won't work.

 

 

 

 

 

Here's what my form currently looks like with the 3 fields added

 

 

 

deelecontactform.th.jpg

 

Uploaded with ImageShack.us

 

 

Many thanks again to Dave L and Dmcwebd.

Another non-developer got it to work.

And it only took 3 days. :D

 

NOW.... I'm determined to get the slide captcha to work.

Link to comment
Share on other sites

Uh oh. I'm having a little problem.

When you select and order ID and product ID, it doesn't transmit that in the email (I added {id_order} and {id_product} to the email file) and it doesn't show up in the administration either. It does include the attachments though.

Are you having the same problem?

Link to comment
Share on other sites

Did you get the slide captcha working?

 

...

 

deelecontactform2.th.jpg

 

I figured out what went wrong with the slide captcha thanks to your last post about it.

I used the interface to upload it rather than unzip it and upload it manually.

That put it in modules > slidecaptcha > slidecaptcha.

But that wasn't all. It just didn't upload it properly so I deleted it all and uploaded it myself.

And it works. Hopefully customers can figure out what to do there. I have to see how accessible that is on a mobile device.

 

That's twice that you've saved the day. Thanks a million.

Link to comment
Share on other sites

  • 2 months later...

I made the form and it's working fine, but I don't see in admin panel the additional fields info. Do you see these informations like company name from the new fields?

 

I want to apear in this mail the subject name too, when I choose a subject and I use same mail, I want to apear the subject like webmaster, customer service...

Can somebody help me?

Link to comment
Share on other sites

  • 1 month later...

hello there,

i would like to know if there is any way to make some fields shown only when a specific department is selected

i want to have a choice where people can send me some specifications of their used mobile and fotos of it in case they want to sell it so only when they choose the option of "used phones" the extra fields would come up

 

i would also like to know if there is a chance to have a dropdown list of mobile phone manufacturers so the customer can choose from

 

so the fields would be:

the first for are globally shown independently of what you will choose on the department dropdown

*firstname

*lastname

*email

*phone number

*textarea

 

*manufacturer - dropdown list from the list of manufacturers i have with an option of "other" where a field would come up to write your manufacturer in case i dont have it on the list

 

*model of mobile phone

date of buying

warranty expiration date

an textarea where the customer can write more details like if it is updated to the latest version or if they have extra parts

and an "upload fotos" option so i can check the condition of it

 

prestashop version 1.4.7.0

 

i know its too much to ask but if you could help me out on this, ill make it work and upload the files so the other people can have them and modify them at their pleasure

 

i am from greece,so, sorry for my english!

Link to comment
Share on other sites

  • 4 weeks later...

If I am reading this correctly, the tutorial involves changing the Controller file.

 

What is the "correct" way to put this into an Override file (v 1.4.7) so that it doesn't get overwritten in the next version update?

 

EDIT:

This thread seems to lead the way

http://stackoverflow.com/questions/10320382/how-to-customize-register-and-contact-forms-in-prestashop

Edited by TWDesign (see edit history)
  • Like 1
Link to comment
Share on other sites

Great tutorial! Thanks a lot

 

On 1.4.7.0 works perfectly! But I think it must be implemented....

 

It would be complete if the field I add are visible also in "Admin Customer Threads" in Back Office.

 

I try do do it but I don't have been able.

 

Someone did it?

Link to comment
Share on other sites

  • 5 weeks later...

Refering back to DmcWebd's original tutorial post, how do I make some of the new fields "non-required"?

 

Edit: *Solved*

 

To make a field "required" you must add the following "elseif" statement after the part where it checks for a bad file extension

 

elseif (!($street = nl2br2(Tools::getValue('street'))))
		    $this->errors[] = Tools::displayError('Street cannot be blank');

 

if you don't want to make them required you can comment those lines out

but it seems that you will then need to add

 

$street = Tools::htmlentitiesUTF8(Tools::getValue('street'));

 

just after

 

$message = Tools::htmlentitiesUTF8(Tools::getValue('message'));

Edited by TWDesign (see edit history)
Link to comment
Share on other sites

  • 1 month later...

Hello, i'm on prestashop 1.7.8.2 and this won't work, i modified the contact-form.tpl, contactcontroller.php, contact.txt and contact.html to add a field "telephone" like the tuto on page 1. There is no error when i send the form but i don't receive the data for the new field "telephone".

 

Anybody knows what can be the problem?

 

Here's my 4 modifed files:

https://www.dropbox.com/s/jvee536xzaj04vk/contactform.zip

 

Thanks

Link to comment
Share on other sites

  • 5 weeks later...

This worked perfectly except for one small issue -- it's the same as jiugdf's issue. The email that goes out to the sender, the new fields are in the email ... but the email that goes to the store owner just has the placeholders : {companyname} {phone}, etc.

 

Any ideas?

Link to comment
Share on other sites

Found the problem ... Here is the answer ...

 

There are 2 places to put your new fields - compare the two below - about line 175

 

 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), '{companyname}' => stripslashes ($companyname), '{contactperson}' => stripslashes ($contactperson),'{phonenumber}' => stripslashes ($phonenumber), '{country}' => stripslashes ($country)), $from))
  self::$smarty->assign('confirmation', 1);
 else

 

 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), '{companyname}' => stripslashes ($companyname), '{contactperson}' => stripslashes ($contactperson),'{phonenumber}' => stripslashes ($phonenumber), '{country}' => stripslashes ($country)), $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), '{companyname}' => stripslashes ($companyname), '{contactperson}' => stripslashes ($contactperson),'{phonenumber}' => stripslashes ($phonenumber), '{country}' => stripslashes ($country)), $from))
  self::$smarty->assign('confirmation', 1);
 else

Link to comment
Share on other sites

  • 4 weeks later...
  • 4 weeks later...

Are you trying to implement all of the field additions or just the phone number.

 

If just the phone number I can PM you the ContactController.php and contact-form.tpl files if you'd like.

 

Edit:

 

Actually I'll add them here in case anyone else would like to use them

 

Just remame the old file first so that you can revert back if it doesn't work for you.

 

Don't forget to force compile to get the changes to the .tpl file to implement.

 

I used your files (from you attacment), and I have some problems with Phone Number text area. It isn't where it should be, like other text boxes, and it's name, in this case "Telefon Mobil" appear write with another font. Another error is the fact that the phone number that the client enter in the phone number field, doesn't appear me anywhere. Why?

rubrica_numar_de_telefon.png

I need your help to resolve this situation.

 

Thanks!

 

PS: Also, in your "contact-form.tpl" (from your attachment), at :


 <input type="text" id="email" name="from" value="{$email}" />
{/if}
</p>
<label for="phonenumber">{l s='Mobile phone'}</label>

 

is a litle mistake.

 

The right code is:

 


 <input type="text" id="email" name="from" value="{$email}" </p>
{/if}
<p>
<label for="phonenumber">{l s='Mobile phone'}</label>

 

Sorry for my english!

Edited by boy2litle (see edit history)
Link to comment
Share on other sites

Hello, i'm on prestashop 1.7.8.2 and this won't work, i modified the contact-form.tpl, contactcontroller.php, contact.txt and contact.html to add a field "telephone" like the tuto on page 1. There is no error when i send the form but i don't receive the data for the new field "telephone".

 

Anybody knows what can be the problem?

 

Here's my 4 modifed files:

https://www.dropbox....contactform.zip

 

Thanks

 

Hello jiugdf!

 

Maybe you cameback with another link, because this one is no longer working.

I have reciving this message:

"Nothing Here

 

The file you are looking for has been deleted or moved."

 

Thanks!

Link to comment
Share on other sites

  • 2 weeks later...

As mentioned before i'm not a php programmer but with hard work I figured my self as people on the forum that knows how to do it, couldn't be bothered explaining it for free.

 

This is for 1.4+ to work with your contact form that has attachment enabled.

 

I will show you the lines that I have added to my form, but you can change to the ones that you need by changing the values.

 

There are few files that has to be edited:

MAKE SURE TO MAKE A BACK UP OF ALL THESE FILES BEFORE EDITING THEM

/controllers/ContactController.php

/themes/your-theme/contact-form.tpl

/mails/en(or and other languages using)/contact.html

/mails/en(or and other languages using)/contact.txt

/mails/en(or and other languages using)/contact_form.html

/mails/en(or and other languages using)/contact_form.txt

 

 

 

/controllers/ContactController.php

Around the like 93 you will see:

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');
		else

 

After the line $this->errors[] = Tools::displayError('Bad file extension'); and before else make a space and add this code:

elseif (!($companyname = nl2br2(Tools::getValue('companyname'))))
	$errors[] = Tools::displayError('Comapny name cannot be blank');

and it should look like this with many others if you need:

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 (!($companyname = nl2br2(Tools::getValue('companyname'))))
	$errors[] = Tools::displayError('Comapny name cannot be blank');
	elseif (!($contactperson = nl2br2(Tools::getValue('contactperson'))))
	$errors[] = Tools::displayError('Contact Person cannot be blank');
	elseif (!($phonenumber = nl2br2(Tools::getValue('phonenumber'))))
	$errors[] = Tools::displayError('Phone Number cannot be blank');
	elseif (!($country = nl2br2(Tools::getValue('country'))))
	$errors[] = Tools::displayError('Country cannot be blank');

		else

Around the line 156 you have this code:

if (Mail::Send((int)(self::$cookie->id_lang), 'contact', Mail::l('Message from contact form'), 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'), array('{message}' => stripslashes($message)), $from))
					self::$smarty->assign('confirmation', 1);

and you have to add:

'{companyname}' => stripslashes ( $companyname ),

the result should look like this:

if (Mail::Send((int)(self::$cookie->id_lang), 'contact', Mail::l('Message from contact form'), array('{email}' => $from, '{message}' => stripslashes($message), '{companyname}' => stripslashes ( $companyname ), '{contactperson}' => stripslashes ( $contactperson ),'{phonenumber}' => stripslashes ( $phonenumber ), '{country}' => stripslashes ( $country )), $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), '{companyname}' => stripslashes ( $companyname ), '{contactperson}' => stripslashes ( $contactperson ),'{phonenumber}' => stripslashes ( $phonenumber ), '{country}' => stripslashes ( $country )), $from))
					self::$smarty->assign('confirmation', 1);

Then on the line 205 you have 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)), $from);
						self::$smarty->assign('confirmation', 1);

And you should add:

'{companyname}' => stripslashes ( $companyname ),

And should look like 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), '{companyname}' => stripslashes ( $companyname ), '{contactperson}' => stripslashes ( $contactperson ),'{phonenumber}' => stripslashes ( $phonenumber ), '{country}' => stripslashes ( $country )), $from);
						self::$smarty->assign('confirmation', 1);

 

This was the most complicated part.

Now comes the next file which is the contact-form.tpl

Find a place where you want to add the new forms on your page and add:

<p>
		<label for="companyname">{l s='Company Name'}</label>
		<input type="text" id="companyname" name="companyname" value="{if isset($companyname)}{$companyname|escape:'htmlall':'UTF-8'|stripslashes}{/if}" />
	</p>

then you make sure all the values match the values from the previous file, the complete forms should look like this:

<p>
		<label for="companyname">{l s='Company Name'}</label>
		<input type="text" id="companyname" name="companyname" value="{if isset($companyname)}{$companyname|escape:'htmlall':'UTF-8'|stripslashes}{/if}" />
	</p>
	<p>
		<label for="contactperson">{l s='Contact Person'}</label>
		<input type="text" id="contactperson" name="contactperson" value="{if isset($contactperson)}{$contactperson|escape:'htmlall':'UTF-8'|stripslashes}{/if}" />
	</p>
	<p>
		<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>
	<p>
		<label for="country">{l s='Country'}</label>
		<input type="text" id="country" name="country" value="{if isset($country)}{$country|escape:'htmlall':'UTF-8'|stripslashes}{/if}" />
	</p>

Now that file is done, the next files are the mail files which you will be able to receive and the customer also receive the mail.

For the TXT files you add:

Company name: {companyname}

Contact person: {contactperson}

Phone number: {phonenumber}

Country: {country}

and for the HTML files you add:

Company name: {companyname}
			<br><br>
			Contact Person: {contactperson}
			<br><br>
			Phone Number: {phonenumber}
			<br><br>
			Country: {country}
			<br><br>

 

And next step is to test it out. if you follow and make sure all the values match for all the files, then it will work without any problem.

I hope it helps

Thats great,

 

Thanks very much for this. I'll give it a go and let you know it's working for me or not.

 

Thanks again.

 

 

great work Dmcwebd & Dave L

many thanks to you both..

Keep it up :) :) :)

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...

For anyone who has got this to work so that the extra fields are shown in the emails, but would also like them to appear in the Customer Service tab of the Back Office I have found a solution.

 

Please open ContactController.php and around line 205 you should see the following:

 

$cm->message = htmlentities($message, ENT_COMPAT, 'UTF-8');

 

Replace this line with the following two lines:

 

$new_string = $message . "<br /><br />Phone Number: " . $phonenumber;
$cm->message = htmlentities($new_string, ENT_COMPAT, 'UTF-8');

 

Essentially, all I am doing is creating a new variable called "new_string" that contains both the customer's message and the new phone number field on the first line. Feel free to call this something more desriptive if you like. You'll see some HTML in the double quotes where I am pushing the new phone number content onto a separate line away from the message. In the second line I have just replaced the existing "message" variable with the "new_string" one which then saves this to the database!

 

I hope this helps! Not tested in 1.5 yet, but maybe my next challenge.

Edited by aztecmedia (see edit history)
Link to comment
Share on other sites

  • 4 weeks later...

Hi everybody

I tried this solutions on ps1.5.2 everything goes well but there is a problem!!

when I changed or add any line to  ContactController.php, a white page will shown!! Is there any one who know where is the problem?  I attached modified files. I really appreciate if any one help me to adjust this codes for ps 1.5.2

Edited by alirezahonarfar (see edit history)
Link to comment
Share on other sites

  • 4 weeks later...
Hi everybody I tried this solutions on ps1.5.2 everything goes well but there is a problem!! when I changed or add any line to ContactController.php, a white page will shown!! Is there any one who know where is the problem? I attached modified files. I really appreciate if any one help me to adjust this codes for ps 1.5.2

 

Hi alirezahonarfar, I tried adding only contact person and phone number but all I got was an error page! How did you do it? I am on 1.5.2 as well. :(

Link to comment
Share on other sites

  • 5 weeks later...
  • 3 months later...
  • 3 weeks later...
  • 2 weeks later...
  • 3 months later...

Hi, i managed to make it partially work on ps 1.5.x

 

But i have a 'label' issue now, i mean, the fields companyname and phonenumber do appear on form, and on email when received.

 

But they just show it like:

 

"Telefono: {phonenumber}" or "Compañia: {companyname}"

 

This is my code on "ContactController":

public function postProcess()
	{
		if (Tools::isSubmit('submitMessage'))
		{    ....

else if (!Validate::isCleanHtml($message))
				$this->errors[] = Tools::displayError('Invalid message');
			elseif (!($companyname = Tools::getValue('companyname')))
		        $this->errors[] = Tools::displayError('Comapny name cannot be blank');
			elseif (!($phonenumber = Tools::getValue('phonenumber')))
				$this->errors[] = Tools::displayError('Phone Number cannot be blank');
			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. ');...

Then on same file:

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, $contact->companyname, $contact->phonenumber, $fileAttachment))
									$this->errors[] = Tools::displayError('An error occurred while sending the message.');

On contact-form.tpl:

<p class="text">
			<label for="companyname">{l s='Compañia'}</label>
			<input type="text" id="companyname" name="companyname" value="{if isset($companyname)}{$companyname|escape:'htmlall':'UTF-8'|stripslashes}{/if}" />
			</p>
			<p class="text">
			<label for="phonenumber">{l s='Teléfono'}</label>
			<input type="text" id="phonenumber" name="phonenumber" value="{if isset($phonenumber)}{$phonenumber|escape:'htmlall':'UTF-8'|stripslashes}{/if}" />
		    </p>

contact.txt: 

Compañia: {companyname}
 
Teléfono: {phonenumber}

contact.html:

<tr>
		Compañia: {companyname}<br><br>
		</tr>
		<tr>Teléfono: {phonenumber}
		<br><br>
		</tr>

contact_form.txt:

Su mensaje ha sido enviado correctamenta a nuestro centro de atención al Cliente. 

Compañia: {companyname}
 
Teléfono: {phonenumber}

contact_form.html:

<td align="left">Su mensaje se envio exitósamente.<br><br /> Mensaje: {message}<br /><br /> 
		<tr>
		Compañia: {companyname}<br><br>
		</tr>
		<tr>Teléfono: {phonenumber}
		<br><br>
		</tr>

Any ideas?

Link to comment
Share on other sites

  • 10 months later...

Hi guys, I would like to ask you one question - how can I reset all settings for this contact form for registration new order from customer´s side? and also for fast order without registration? I have made some changes but I figured out that I will need more info added there. I followed some manual from PS forum to delete fields. Could you pls tell me which files have to be recopied again to get default setting? 

 

contact.html+contact_form.txt:+contact.html:+contact.txt: + contact-form.tpl:+ContactController": - all these have to be rewritten or something else too?

thank you much

Edited by domorodecmezilidmi (see edit history)
Link to comment
Share on other sites

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...