hideaki Posted June 2, 2011 Share Posted June 2, 2011 Hi,I'm new to PrestaShop, jsut started learning it only 2 days ago. I would like to have a custom Contact Us page, and try messing around with .php and .tpl files. However, I was wondering whether it's possible to include a chunk of PHP code mixed with HTML in the .tpl file? The code goes: <?php if(isset($_POST['send'])){ $emailFrom = "[email protected]"; $emailTo = "[email protected]"; $subject = "Contact Form Submission"; $name = strip_tags($_POST['name']); $email = strip_tags($_POST['email']); $message = strip_tags(stripslashes($_POST['message'])); $body = "Name: ".$name."\n"; $body .= "Email: ".$email."\n"; $body .= "Message: ".$message."\n"; $headers = "From: ".$emailFrom."\n"; $headers .= "Reply-To:".$email."\n"; if($_SESSION['security_code'] == $_POST['security_code']){ $success = mail($emailTo, $subject, $body, $headers); if ($success){ echo ' Your enquiry has been sent and we will get back to you shortly.'; } } else { echo ' Please enter the CAPTCHA code again.'; } } else { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="contact" name="contact"> Name <input type="text" id="name" name="name" class="required" minlength="2"/> E–mail <input type="text" id="email" name="email" class="required email"/> Message <textarea id="message" name="message" cols="50" rows="10" class="required"></textarea> Are you human? Enter captcha <input type="text" id="security_code" name="security_code" autocomplete="off" class="required"/> Send! </form> <?php } ?> How should I go about incorporating this script with the .tpl/.php files? I hope someone can provide me with suggestions. Thanks! Link to comment Share on other sites More sharing options...
Bruno Leveque Posted June 2, 2011 Share Posted June 2, 2011 Hi,The best way to do this is:In the .php file, instead of "echo": if ($success) { $smarty->assign('success', 1); } else { $smarty->assign('error', 1); } and then in the .tpl file: {if isset($success) && $success == 1} Your enquiry has been sent and we will get back to you shortly. {/if} {if isset($error) && $error == 1} Please enter the CAPTCHA code again. {/if} I hope this helps ++ Link to comment Share on other sites More sharing options...
hideaki Posted June 2, 2011 Author Share Posted June 2, 2011 Hi Bruno,Thanks for your quick reply. However, I'm unaware of how I should break down the codes to the .php and .tpl files respectively. If you noticed the codes I mentioned above, you can simply put them all (both the code and design) in a regular .php file and it will work fine. The reason I'm confused is that there's a break of PHP coding for HTML form in between that goes: } else { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="contact" name="contact"> Name <input type="text" id="name" name="name" class="required" minlength="2"/> E–mail <input type="text" id="email" name="email" class="required email"/> Message <textarea id="message" name="message" cols="50" rows="10" class="required"></textarea> Are you human? Enter captcha <input type="text" id="security_code" name="security_code" autocomplete="off" class="required"/> Send! </form> <?php } ?> And the PHP code continues with a simple closure. How do I break this code, and which part should go into the .php and .tpl files? Link to comment Share on other sites More sharing options...
Bruno Leveque Posted June 2, 2011 Share Posted June 2, 2011 This whole "else" part should be in the .tpl file, delete it from the PHP.Then in the .tpl put: > {if !isset($smarty.post.send)} <form action="{$request_uri}" method="post" id="contact" name="contact"> </pre> <fieldset> Name <input type="text" id="name" name="name" class="required" minlength="2"/> E–mail <input type="text" id="email" name="email" class="required email"/> Message <textarea id="message" name="message" cols="50" rows="10" class="required"></textarea> Are you human? Enter captcha <input type="text" id="security_code" name="security_code" autocomplete="off" class="required"/> Send! </fieldset> <br></form> Note that I replaced the form action value by $request_uri (a Smarty global variable in PrestaShop).Regards, 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