Guest Posted May 13, 2013 Share Posted May 13, 2013 Hey everyone, Was wondering what the best option for creating a custom form in a CMS page that sends to a selected email? Is the best option going through a website that charges for form submissions >100 a month, or is there a way to achieve this within prestashop? Thanks in advance, Link to comment Share on other sites More sharing options...
vekia Posted May 14, 2013 Share Posted May 14, 2013 You want to create contact form in CMS page? Am I right? Link to comment Share on other sites More sharing options...
Guest Posted May 15, 2013 Share Posted May 15, 2013 Hey vekia, Thanks so much for the reply! Yes, right now I have a custom CMS page setup and then link that on the tophorizontalmodule. Is that the best way to go about this? I'm not sure how to proceed. Thanks! Link to comment Share on other sites More sharing options...
vekia Posted May 15, 2013 Share Posted May 15, 2013 You can create form in cms.tpl file located in your theme (remember about if condition to check cms id! otherwise form will appear on each category page). Then in CMS controller you can add php script to send mail regards 1 Link to comment Share on other sites More sharing options...
Guest Posted May 15, 2013 Share Posted May 15, 2013 Hey vekia, Thanks for the reply! Much appreciated. I understand the first part of your instructions, however I am a little lost on the second part. EDIT: Trying to understand on my own. Will update. Thanks, Link to comment Share on other sites More sharing options...
Guest Posted May 16, 2013 Share Posted May 16, 2013 Okay so I have made some progress. I found two ways to achieve a duplicate of the contact-us form. First was through your method vekia, which was to add into the cms.tpl file using a check cms id function. Quote <div class="rte{if $content_only} content_only{/if}"> {$cms->content} {if $cms->id==7} INSERT CODE FROM CONTACT-FORM.TPL {/if} </div> However, I did not prefer this solution because of the URL generated with a CMS page. I then also noted this solution I found by searching around. I duplicated 3 files; 1) ~/contact-form.php --> ~/customization-form.php 2) ~/controllers/front/ContactController.php --> ~/controllers/front/CustomizationController.php 3) ~/themes/YOURTHEME/contact-form.tpl --> ~/themes/YOURTHEME/customization-form.php Then in CustomizationController I edited line 27 to the following: Quote class CustomizationControllerCore extends FrontController Then line 29 to: Quote public $php_self = 'customization'; And line 255 to: Quote $this->setTemplate(_PS_THEME_DIR_.'customization-form.tpl'); Now I am in the process of changing the form around. I am able to add forms into the tpl file in my theme direction, but I am unsure of how to have those fields from the form emailed to me once customers submit it. Could anyone shine some light on that? I would really appreciate it. For example, I can put this in the tpl file customization.tpl: Quote <p class="text"> <label>Dimensions</label> <input type="text" id="dimensions" /> </p> But I am unsure of how to modify the CustomizationController in order for that field to be included in the email that is sent to me. I would really appreciate any help. Thanks in advance, Link to comment Share on other sites More sharing options...
Guest Posted May 18, 2013 Share Posted May 18, 2013 Hey guys, I just figured out the solution to my problem so I thought I would post it here! The first method I posted turned out to be the best. In this case the second method was a good way to make a duplicate of the contact-form, however it is not very customizable for the PHP novice such as myself. So using the first method I inserted my HTML form within the cms.tpl using: {if $cms->id==7}{/if} Then making sure to use form action="../themes/yourtheme/mail.php" within the beginning of the form and then within mail.php (or whatever you name it. For example mine is: <form action="../themes/yourtheme/mail.php" method="POST"> <p>Name</p> <input type="text" name="name"> <p>Email</p> <input type="text" name="email"> <p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br /> <input type="submit" value="Send"><input type="reset" value="Clear"> </form> Then for my mail.php I included this; $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $formcontent="From: $name \n Message: $message"; $recipient = "[email protected]"; $subject = "Contact Form"; $mailheader = "From: $email \r\n"; mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); echo "Thank You!"; This enabled me to have it sent to a blank page with "Thank you!" and it would send the email. But I wanted it to redirect you to a thank you page on the site, so I made a custom CMS page saying thank you and we will get back to you shortly using at the top of mail.php: <?php header( 'Location: http://www.domain.co...ent/id-pagename' ); This will allow a nice redirect. Anyways, hope this helps anyone else that is looking for this solution. All the best, Link to comment Share on other sites More sharing options...
Guest Posted May 31, 2013 Share Posted May 31, 2013 Thanks ericbi! Hope it helped you out! Link to comment Share on other sites More sharing options...
grafician Posted June 2, 2013 Share Posted June 2, 2013 Nice post, thank you, but in my case at prestashop 1.5.4.1 if i have mail.php in root after i insert data i get error 404 at this url http://localhost/ro/content/Mail.php, of course i dont have ro/content in my cms.tpl just this <form action="Mail.php" method="POST"> How can i lose ro/content? Link to comment Share on other sites More sharing options...
Guest Posted June 2, 2013 Share Posted June 2, 2013 Hey turculetztz, You need to edit "cms.tpl" in your theme folder and add mail.php in the root of your theme folder, not the root of your prestashop installation. Try changing your form initial tag to: <form action="../themes/yourtheme/mail.php" method="POST" enctype="multipart/form-data"> Although that shouldn't really make a difference. Are you wrapping your form with {if $cms->id==7}<form></form>{/if} or whatever is the ID number of your CMS page is? Best, eggo Link to comment Share on other sites More sharing options...
grafician Posted June 2, 2013 Share Posted June 2, 2013 Yea, thx, it's ok now with <form action="/themes/default/Mail.php" method="POST"> and mail.php there I'm not yet familiar with some things:) Link to comment Share on other sites More sharing options...
silentRun Posted June 3, 2013 Share Posted June 3, 2013 Nice tutorial mate, well done ! Maybe someone is interested in implementing ajax-jquery to the form, so it doesn't need to reload the page to send the information: Ajax contact form 1 Link to comment Share on other sites More sharing options...
Guest Posted June 3, 2013 Share Posted June 3, 2013 That would be a great implementation! But unfortunately out of my realm. I'm working on having an attachment that the customer can upload the server/be sent by email to us. If I come to a solution I will post it here. I would appreciate if anyone else would be able to expand upon this to add the functionality if they have the expertise. If not, when I find the solution I will post it here! Best, Link to comment Share on other sites More sharing options...
silentRun Posted June 3, 2013 Share Posted June 3, 2013 You could start with this : Send file by contact form Good luck Link to comment Share on other sites More sharing options...
grafician Posted July 5, 2013 Share Posted July 5, 2013 roflymego, in the end I made a firebug capture on the original contact form that has the upload field, then a paste in cms.tpl everything works great, for sure it's not the correct way but i don't care as long as she serve my purpose, also no need for mail.php prestashop 1.5.4.1, my code: <!-- custom form--> {if $cms->id==9} <div id="personalizat"> <form enctype="multipart/form-data" class="std" method="post" action="/ro/contact-us"> <fieldset> <h3>trimitere mesaj</h3> <p class="select"> <label for="id_contact">Subiect</label> <select onchange="showElemFromSelect('id_contact', 'desc_contact')" name="id_contact" id="id_contact"> <option value="0">-- Alege --</option> <option value="2">Customer service</option> <option value="1">Webmaster</option> </select> </p> <p class="desc_contact" id="desc_contact0"> </p> <p style="display:none; margin-left:10px;" class="desc_contact" id="desc_contact2"> For any question about a product, an order </p> <p style="display:none; margin-left:10px;" class="desc_contact" id="desc_contact1"> If a technical problem occurs on this website </p> <p class="text"> <label for="email">Adresa de e-mail</label> <input type="text" value="" name="from" id="email"> </p> <p class="text"> <label for="fileUpload">Atașează fișier</label> <input type="hidden" value="2000000" name="MAX_FILE_SIZE"> <input type="file" id="fileUpload" name="fileUpload"> </p> <p class="textarea"> <label for="message">Mesaj</label> <textarea cols="10" rows="15" name="message" id="message"></textarea> </p> <p class="submit"> <input type="submit" onclick="$(this).hide();" class="button_large" value="Trimite" id="submitMessage" name="submitMessage"> </p> </fieldset> </form> </div> <!-- end of custom form --> Link to comment Share on other sites More sharing options...
hahamobile Posted January 14, 2014 Share Posted January 14, 2014 Yea, thx, it's ok now with <form action="/themes/default/Mail.php" method="POST"> and mail.php there I'm not yet familiar with some things:) hi guys. I did exactly what you said. and the form looks good within the CMS. but when I try to send an message using the form. it does not send. and gives me an 404 error message. I set up the recipient email according to what you said. please help, where I got it wrong? Link to comment Share on other sites More sharing options...
vekia Posted January 14, 2014 Share Posted January 14, 2014 just wondering why you use /themes/default/Mail.php as an action param have you got this file? 1 Link to comment Share on other sites More sharing options...
Guest Posted January 14, 2014 Share Posted January 14, 2014 Make sure your path to mail.php is correct. Link to comment Share on other sites More sharing options...
hahamobile Posted January 14, 2014 Share Posted January 14, 2014 just wondering why you use /themes/default/Mail.php as an action param have you got this file? thank you vekia. I figured out where the problem was. it is working now. thanks. Link to comment Share on other sites More sharing options...
vekia Posted January 15, 2014 Share Posted January 15, 2014 thank you for information, may i know where the problem was? with action="" param? Link to comment Share on other sites More sharing options...
hashmi photos Posted February 3, 2014 Share Posted February 3, 2014 i need this type of contact us page how can i creat this page ??contact US form link>>> www.theshop247.com/contact-us Link to comment Share on other sites More sharing options...
tozi Posted February 3, 2014 Share Posted February 3, 2014 Works great. Thanks a lot. Link to comment Share on other sites More sharing options...
miroslavK Posted February 20, 2014 Share Posted February 20, 2014 i need this type of contact us page how can i creat this page ?? contact US form link>>> www.theshop247.com/contact-us simply but funcional for me any idea of possible problems? insert if...../if into the cms.tpl if you do not need to have pressed "CONTAC US" or "CUSTOMER SERVIS" button <div class="rte{if $content_only} content_only{/if}"> {$cms->content} {if $cms->id == 6} // 6 ->ID of CMS - contact us, change it if needed {Tools::redirect('index.php?controller=contact')} {/if} </div> Link to comment Share on other sites More sharing options...
salsaweb Posted June 28, 2014 Share Posted June 28, 2014 (edited) Hello I need to create a form with these 5 areas:namesurnameemailCurriculum (select file)SendI tried in every way, can you help?Using prestashop 1.6.8Thank you!SW Edited June 28, 2014 by salsaweb (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted June 28, 2014 Share Posted June 28, 2014 prestashop 1.6.8 ? perhaps you mean 1.6.0.8 btw. default form allows to add files you can translate this field to "curriculum" under localization > translations > front office translations Link to comment Share on other sites More sharing options...
salsaweb Posted June 28, 2014 Share Posted June 28, 2014 Thanks! But I don't duplicate contactblock, but i need create a new contactblock call this workus, because i need create a module for people job with us. I want put a link in navbar near "contact us" and link open page with this form I'm very confused Link to comment Share on other sites More sharing options...
jjryeste Posted December 5, 2014 Share Posted December 5, 2014 Hello is possible, create and other email diferent , example questiont_form.html for contact_form.html thank you Link to comment Share on other sites More sharing options...
Guest Posted December 6, 2014 Share Posted December 6, 2014 jjryeste, You could simply create a separate Contact category instead of "Webmaster" or "Customer Support" etc, and note the value of the new addition. Then from there edit your tpl file and make the option value ="#" the new number that has been assigned to the value you created. Make that the only option (in other words remove the foreach loop in the option html under subject heading) and even hide the subject heading altogether with display:none; if you wish. Make these edits in the tpl file for your new contact form. Update for 1.6.x users, for creating a duplicate contact form the procedure is the same except for you only need to copy the controller and the theme tpl file. There is no contact.php in the home anymore. Cheers! Link to comment Share on other sites More sharing options...
Guest Posted January 22, 2015 Share Posted January 22, 2015 Depends on if you used the CMS method (which is kind of a bit of a hacked up version which I really wouldn't recommend using) then it would be under the CMS id that you used for the tutorial. If you used the controller duplicate method then it will be under the new URL that you have to specify under SEO and URLs based on the new tpl file and controller. Good luck! Link to comment Share on other sites More sharing options...
shri Posted January 22, 2015 Share Posted January 22, 2015 Oh great. I got it. Its working the way you said it would. I am so amazed how you figured this out all on your own. Rather than having to purchase a new contact form, which my boss would not be willing to pay for, you gave a brilliant solution. Thanks buddy. Link to comment Share on other sites More sharing options...
shri Posted January 23, 2015 Share Posted January 23, 2015 Hi , I noticed that the form worked just fine but i have an error in other cms page. Does anyone have any idea what this error is and help me get rid of it. Notice: Undefined index: cms in ../public_html/cache/smarty/compile/cb/c6/4b/cbc64b6a11f38b04ee47d2912acce5d10ab649ff.file.cms.tpl.php on line 41Notice: Trying to get property of non-object in ../public_html/cache/smarty/compile/cb/c6/4b/cbc64b6a11f38b04ee47d2912acce5d10ab649ff.file.cms.tpl.php on line 41Notice: Trying to get property of non-object in ../public_html/cache/smarty/compile/cb/c6/4b/cbc64b6a11f38b04ee47d2912acce5d10ab649ff.file.cms.tpl.php on line 41 This is what line 41 looks like. <?php if ($_smarty_tpl->tpl_vars['cms']->value->id==4){?> Link to comment Share on other sites More sharing options...
kingsinnersoul Posted March 31, 2015 Share Posted March 31, 2015 Thank you for the example and good share. I am facing a problem, where I have two languages in my store, and I placed the mail.php file in the root, themes, and default-bootstrap directory as well. When the form submits, it redirects to mayDomainName.com/lang/mail.php and throws me 404 not found. How can I set the action="" to be relative to the lang? Thanks Link to comment Share on other sites More sharing options...
PipBoy2000 Posted May 19, 2015 Share Posted May 19, 2015 (edited) Hi. How to redirect after submit to the same page instead of some other page in header: location? The solution for add information about product in the form <form action="../themes/yourtheme/mail.php" method="POST"><p>Name</p> <input type="text" name="name"><p>Email</p> <input type="text" name="email"> <input type="hidden" name="product" value="{$product->name|escape:'htmlall':'UTF-8'}"><p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br /><input type="submit" value="Send"><input type="reset" value="Clear"></form> and $message = $_POST['message']; $product = $_POST['product'];$formcontent="From: $name \n About: $product \n Message: $message"; Edited May 19, 2015 by PipBoy2000 (see edit history) Link to comment Share on other sites More sharing options...
shri Posted May 21, 2015 Share Posted May 21, 2015 Hi. How to redirect after submit to the same page instead of some other page in header: location? The solution for add information about product in the form <form action="../themes/yourtheme/mail.php" method="POST"> <p>Name</p> <input type="text" name="name"> <p>Email</p> <input type="text" name="email"> <input type="hidden" name="product" value="{$product->name|escape:'htmlall':'UTF-8'}"> <p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br /> <input type="submit" value="Send"><input type="reset" value="Clear"> </form> and $message = $_POST['message']; $product = $_POST['product']; $formcontent="From: $name \n About: $product \n Message: $message"; Before $message = $_POST['message']; Use this line header('Location:http://UrlOfThePageYouWant'); It should redirect to whatever page you are after Link to comment Share on other sites More sharing options...
harrisatria Posted October 1, 2018 Share Posted October 1, 2018 (edited) "IF" section didn't work for me, i used prestashop 1.7.x the form show in any cms page. help me SOLVED in prestashop 1.7 use var $cms.id Edited October 1, 2018 by harrisatria (see edit history) 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