Jump to content

Create Custom Contact Form on CMS page


Recommended Posts

Hi experts.

 

Im trying to create a custom contact form on my prestashop store.

 

I would like to maintain (if is possible) the same style than the default contact form on my themed store. But if its not possible.. no problem, most important is than works.

 

I wanna create a contact with this fields http://goo.gl/mDAzKY

 

Any idea about some module or code to do this?

 

Thank you for answerd.

 

LuchoFox

Share this post


Link to post
Share on other sites

you you will need to create form fields manually (html code) 

then in CmsController you need to add function to handle this form and send email

Share this post


Link to post
Share on other sites

you you will need to create form fields manually (html code) 

then in CmsController you need to add function to handle this form and send email

 

I understand untill create the HTML code... where i found the CmsController..? add a function..? how can i do that?

 

Can you give me some better idea?

 

Thanks Milos.

 

LuchoFox

Share this post


Link to post
Share on other sites

create form like

<form action="" method="post">
... FIELDS
... FIELDS
... FIELDS
<input type="submit" name="customcontact" value="submit" />
</form>

then in controllers/front/CmsController.php file, in init() function add code like this:

if (isset($_POST['customcontact'])){
mail function here
}

Share this post


Link to post
Share on other sites

 

create form like

<form action="" method="post">
... FIELDS
... FIELDS
... FIELDS
<input type="submit" name="customcontact" value="submit" />
</form>

then in controllers/front/CmsController.php file, in init() function add code like this:

if (isset($_POST['customcontact'])){
mail function here
}

Hi Milos, thanks for the advide.

 

I added a simple code from HTML as test

<form id="so-form" action="" method="post" name="so-form">
<p>First Name: <label for="so-firstname"></label> <input type="text" name="so-firstname" /></p>
<p>Last Name: <label for="so-lastname"></label> <input type="text" name="so-lastname" /></p>
<p class="submit"><input class="button" type="submit" name="send" value="Send" /></p>
</form>

When i save the CMS page i receive this message: The content field (English (English)) is invalid.

 

Why happen this..?

 

Thanks

 

LuchoFox

Share this post


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

What would be the best way to add Form Fields validation?  Other than inline javascript...

 

you can validate variables in postProcess() function located in controllers/front/ContactController.php

Share this post


Link to post
Share on other sites

Vekia, I appreciate your reply but I had decided to create these pages as "stand-alone pages" with my own javascript in order to avoid too much customization on my website that will then prevent me from upgrading to newer versions.

Share this post


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

Hi,

 

I would like to create a form in CMS page. I found a webside were I can make templates and I tried to put the html code in the content CMS page, in HTML mode, but It always says that Content is not valid. I am not an expert so what should I do that I can put this code and works in the content? our webside is chic-n-luxury.com. Thanks in advance.

 

<!DOCTYPE html>
<html>
<head>
 
<title>
Customer Satisfaction Survey
</title>
 
<!-- Meta Tags -->
<meta charset="utf-8">
<meta name="generator" content="Wufoo">
<meta name="robots" content="index, follow">
 
<!-- CSS -->
<link href="css/structure.css" rel="stylesheet">
<link href="css/form.css" rel="stylesheet">
 
<!-- JavaScript -->
<script src="scripts/wufoo.js"></script>
 
<!--[if lt IE 10]>
<![endif]-->
</head>
 
<body id="public">
<div id="container" class="ltr">
  <form id="form1" name="form1" class="wufoo  page" accept-charset="UTF-8" autocomplete="off" enctype="multipart/form-data" method="post" novalidate
  <header id="header" class="info">
<h2>Customer Satisfaction Survey</h2>
<div>Please take a few moments to complete this satisfaction survey. </div>
</header>
 
<ul>
 
<li id="foli208" class="notranslate      ">
<fieldset>
<![if !IE | (gte IE 8)]>
<legend id="title208" class="desc">
Overall, how satisfied were you with the product / service?</legend>
<![endif]>
<!--[if lt IE 8]>
<label id="title208" class="desc">
Overall, how satisfied were you with the product / service?
</label>
<![endif]-->
<div>
<input id="radioDefault_208" name="Field208" type="hidden" value="" />
<span>
<input id="Field208_0" name="Field208" type="radio" class="field radio" value="N/A" tabindex="1" />
<label class="choice" for="Field208_0" >
N/A</label>
</span>
<span>
<input id="Field208_1" name="Field208" type="radio" class="field radio" value="Neutral" tabindex="2" />
<label class="choice" for="Field208_1" >
Neutral</label>
</span>
<span>
<input id="Field208_2" name="Field208" type="radio" class="field radio" value="Unsatisfied" tabindex="3" />
<label class="choice" for="Field208_2" >
Unsatisfied</label>
</span>
<span>
<input id="Field208_3" name="Field208" type="radio" class="field radio" value="Very Satisfied" tabindex="4" />
<label class="choice" for="Field208_3" >
Very Satisfied</label>
</span>
<span>
<input id="Field208_4" name="Field208" type="radio" class="field radio" value="Satisfied" tabindex="5" />
<label class="choice" for="Field208_4" >
Satisfied</label>
</span>
<span>
<input id="Field208_5" name="Field208" type="radio" class="field radio" value="Very Unsatisfied" tabindex="6" />
<label class="choice" for="Field208_5" >
Very Unsatisfied</label>
</span></div>
</fieldset>
</li><li id="foli212" 
class="notranslate      "><label class="desc" id="title212" for="Field212">
What do you dislike about the product / service?
</label>
 
<div>
<textarea id="Field212" 
name="Field212" 
class="field textarea medium" 
spellcheck="true" 
rows="10" cols="50" 
tabindex="7" 
onkeyup=""
 ></textarea>
</div>
</li>
<li id="foli214" class="notranslate      ">
<label class="desc" id="title214" for="Field214">
Email</label>
<div>
<input id="Field214" name="Field214" type="email" spellcheck="false" class="field text medium" value="" maxlength="255" tabindex="8" /> 
</div>
</li>
<li id="foli215" class="notranslate      ">
<label class="desc" id="title215" for="Field215">
Name</label>
<span>
<input id="Field215" name="Field215" type="text" class="field text fn" value="" size="8" tabindex="9" />
<label for="Field215">First</label>
</span>
<span>
<input id="Field216" name="Field216" type="text" class="field text ln" value="" size="14" tabindex="10" />
<label for="Field216">Last</label>
</span></li> <li class="buttons ">
<div>
 
                    <input id="saveForm" name="saveForm" class="btTxt submit" 
    type="submit" value="Submit"
 /></div>
</li>
</ul>
</form> 
 
</div>
<!--container-->
</body>
</html>
 

Share this post


Link to post
Share on other sites

I needed to add a simple contact form to one CMS page and I had to put together pieces from different post. Mainly from here (thank you): http://www.prestashop.com/forums/topic/246845-solved-custom-form/

 

I was surprised to not find more strainght forward information, so I am going to summarize here what I did in case it helps someone else in the future. First you need to extend your TinyMCE, follow the link provided by vekia above.

 

I inserted the form in the HTML editor of my CMS page:

<form action="" method="post" autocomplete="off">
<div><label>NAME</label>
<div><input style="width: 220px; height: 28px;" name="name" type="text" /></div>
</div>
<br />
<div><label>BEST CONTACT</label>
<div><input style="width: 220px; height: 28px;" name="email" type="text" />
<div><spam style="font-style: italic;">(email, phone or both)</spam></div>
</div>
</div>
<br />
<div class="quickformsubject"><label>SUBJECT</label>
<div><input style="width: 220px; height: 28px;" name="subject" type="text" /></div>
</div>
<div><label>YOUR MESSAGE</label>
<div><textarea style="width: 340px; height: 100px;" name="message" rows="6" cols="25"></textarea></div>
</div>
<br />
<div><input class="button" name="quickcontact" value="Contact me" type="submit" /></div>
</form>

The SUBJECT field is a trap for spambots, it is hidden for human users, therefore it should be always empty; if robots fill it out the form dies (more info here: http://riserinteractive.com/stop-form-spam-without-captcha-or-quizzes/)

Add the following to your CSS to hide the trap field:

.quickformsubject {
    display: none;       
}

Last, I added this to my CmsController.php file. It goes inside the funtion function init(), I put it at the end, right after "header('Status: 404 Not Found'); }"

if (isset($_POST['quickcontact'])){
            if ( $_POST['subject'] != '' ) {
                die("ERROR");
            } else {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $formcontent="From: $name \n Email: $email \n Message: $message";
        $recipient = "email@yourdomain.com";
        $subject = "Quick Contact Form";
         $mailheader = "From: $email \r\n";
        mail($recipient, $subject, $formcontent, $mailheader) or die("Error");
        header( 'Location: http://yourdomain.com/store/en/content/16-thank-you' ) ;
            }
        }

The form will redirect the user to a thank you page or any other page you select, it will not sent a confirmation email to the user. It worked for me in PS 1.5.6.1

 

Good luck,

 

 

 

  • Like 5

Share this post


Link to post
Share on other sites
  • 5 months later...
Ok its worked in 1.5.x, but not working with 1.6.x

Can u fix @pietro code  ?

SOLVED

 

... For idiots like me

 

The SUBJECT field is a trap for spambots, it is hidden for human users, therefore it should be always empty;

 

It`s working with PS 1.6.0.8

Edited by ukwyspa (see edit history)

Share this post


Link to post
Share on other sites

Please help.

Im having the same issue trying to embed a jotform.

I'm supposed to paste this embed code into the script.  But, I keep getting invalid content error.

 

<script type="text/javascript" src="http://form.jotform.us/jsform/22101528081138"></script>

 

 

So, I went back and got the source code, which doesn't work either.  Please help....See below.

 

 

<script src="http://max.jotfor.ms/static/prototype.forms.js" type="text/javascript"></script>
<script src="http://max.jotfor.ms/static/jotform.forms.js?3.2.3591" type="text/javascript"></script>
<script src="https://js.jotform.com/vendor/postMessage.min.js" type="text/javascript"></script>
<script src="https://js.jotform.com/WidgetsServer.js" type="text/javascript"></script>
<script type="text/javascript">
   JotForm.init(function(){
      JotForm.setCalendar("20", false);
      JotForm.displayLocalTime("hour_20", "min_20", "ampm_20");
   });
</script>
<link href="http://max.jotfor.ms/static/formCss.css?3.2.3591" rel="stylesheet" type="text/css" />
<link type="text/css" rel="stylesheet" href="http://max.jotfor.ms/css/styles/jottheme.css?3.2.3591" />
<link type="text/css" media="print" rel="stylesheet" href="http://max.jotfor.ms/css/printForm.css?3.2.3591" />
<style type="text/css">
    .form-label-left{
        width:150px !important;
    }
    .form-line{
        padding-top:12px;
        padding-bottom:12px;
    }
    .form-label-right{
        width:150px !important;
    }
    .form-all{
        width:690px;
        background: #000000;
        color:rgb(255, 82, 0) !important;
        font-family:'Arial';
        font-size:14px;
    }
    .form-radio-item label, .form-checkbox-item label, .form-grading-label, .form-header{
        color: rgb(255, 82, 0);
    }

</style>

<link type="text/css" rel="stylesheet" href="http://jotform.us/css/styles/buttons/form-submit-button-push_red.css?3.2.3591"/>
<form class="jotform-form" action="http://submit.jotform.us/submit/22101528081138/" method="post" name="form_22101528081138" id="22101528081138" accept-charset="utf-8">
  <input type="hidden" name="formID" value="22101528081138" />
  <div class="form-all">
    <ul class="form-section">
      <li id="cid_1" class="form-input-wide" data-type="control_head">
        <div class="form-header-group">
          <div class="header-text httal htvam">
            <h1 id="header_1" class="form-header">
              Customize your Apparel.
            </h1>
          </div>
        </div>
      </li>
      <li class="form-line form-line-column form-col-1" data-type="control_image" id="id_25">
        <div id="cid_25" class="form-input-wide">
          <img alt="" class="form-image" border="0" src="http://www.jotform.com/uploads/jasmynn/form_files/CUSTOM logo,Bling Banner.jpg" height="217" width="619" />
        </div>
      </li>
      <li class="form-line form-line-column form-col-1 form-line-column-clear" data-type="control_textbox" id="id_3">
        <label class="form-label form-label-left form-label-auto" id="label_3" for="input_3">
          Name
          <span class="form-required">
            *
          </span>
        </label>
        <div id="cid_3" class="form-input">
          <input type="text" class=" form-textbox validate[required]" data-type="input-textbox" id="input_3" name="q3_name3" size="20" value="" />
        </div>
      </li>
      <li class="form-line form-line-column form-col-1 form-line-column-clear" data-type="control_textbox" id="id_5">
        <label class="form-label form-label-left form-label-auto" id="label_5" for="input_5">
          Phone
          <span class="form-required">
            *
          </span>
        </label>
        <div id="cid_5" class="form-input">
          <input type="text" class=" form-textbox validate[required]" data-type="input-textbox" id="input_5" name="q5_phone" size="20" value="" />
        </div>
      </li>
      <li class="form-line form-line-column form-col-1 form-line-column-clear" data-type="control_textbox" id="id_6">
        <label class="form-label form-label-left form-label-auto" id="label_6" for="input_6">
          Team, School or Organization
          <span class="form-required">
            *
          </span>
        </label>
        <div id="cid_6" class="form-input">
          <input type="text" class=" form-textbox validate[required]" data-type="input-textbox" id="input_6" name="q6_teamSchool" size="20" value="" />
        </div>
      </li>
      <li class="form-line" data-type="control_textbox" id="id_27">
        <label class="form-label form-label-left form-label-auto" id="label_27" for="input_27"> Team, School or Organization Colors </label>
        <div id="cid_27" class="form-input">
          <input type="text" class=" form-textbox" data-type="input-textbox" id="input_27" name="q27_teamSchool27" size="20" value="" />
        </div>
      </li>
      <li class="form-line form-line-column form-col-1 form-line-column-clear" data-type="control_textbox" id="id_7">
        <label class="form-label form-label-left form-label-auto" id="label_7" for="input_7">
          Email
          <span class="form-required">
            *
          </span>
        </label>
        <div id="cid_7" class="form-input">
          <input type="text" class=" form-textbox validate[required]" data-type="input-textbox" id="input_7" name="q7_email" size="20" value="" />
        </div>
      </li>
      <li class="form-line form-line-column form-col-1 form-line-column-clear" data-type="control_checkbox" id="id_8">
        <label class="form-label form-label-left form-label-auto" id="label_8" for="input_8"> Products of Interest </label>
        <div id="cid_8" class="form-input">
          <div class="form-single-column">
            <span class="form-checkbox-item" style="clear:left;">
              <input type="checkbox" class="form-checkbox" id="input_8_0" name="q8_productsOf8[]" value="Bling Tees" />
              <label for="input_8_0"> Bling Tees </label>
            </span>
            <span class="clearfix">
            </span>
            <span class="form-checkbox-item" style="clear:left;">
              <input type="checkbox" class="form-checkbox" id="input_8_1" name="q8_productsOf8[]" value="Hoodies" />
              <label for="input_8_1"> Hoodies </label>
            </span>
            <span class="clearfix">
            </span>
            <span class="form-checkbox-item" style="clear:left;">
              <input type="checkbox" class="form-checkbox" id="input_8_2" name="q8_productsOf8[]" value="Leotards" />
              <label for="input_8_2"> Leotards </label>
            </span>
            <span class="clearfix">
            </span>
            <span class="form-checkbox-item" style="clear:left;">
              <input type="checkbox" class="form-checkbox" id="input_8_3" name="q8_productsOf8[]" value="Warmups" />
              <label for="input_8_3"> Warmups </label>
            </span>
            <span class="clearfix">
            </span>
            <span class="form-checkbox-item" style="clear:left;">
              <input type="checkbox" class="form-checkbox" id="input_8_4" name="q8_productsOf8[]" value="Jackets" />
              <label for="input_8_4"> Jackets </label>
            </span>
            <span class="clearfix">
            </span>
            <span class="form-checkbox-item" style="clear:left;">
              <input type="checkbox" class="form-checkbox" id="input_8_5" name="q8_productsOf8[]" value="Car Decals" />
              <label for="input_8_5"> Car Decals </label>
            </span>
            <span class="clearfix">
            </span>
            <span class="form-checkbox-item" style="clear:left;">
              <input type="checkbox" class="form-checkbox" id="input_8_6" name="q8_productsOf8[]" value="Tanks" />
              <label for="input_8_6"> Tanks </label>
            </span>
            <span class="clearfix">
            </span>
            <span class="form-checkbox-item" style="clear:left;">
              <input type="checkbox" class="form-checkbox" id="input_8_7" name="q8_productsOf8[]" value="Other" />
              <label for="input_8_7"> Other </label>
            </span>
            <span class="clearfix">
            </span>
          </div>
        </div>
      </li>
      <li class="form-line" data-type="control_textbox" id="id_28">
        <label class="form-label form-label-left form-label-auto" id="label_28" for="input_28">
          Approximate Quantity Needed
          <span class="form-required">
            *
          </span>
        </label>
        <div id="cid_28" class="form-input">
          <input type="text" class=" form-textbox validate[required]" data-type="input-textbox" id="input_28" name="q28_approximateQuantity" size="20" value="" />
        </div>
      </li>
      <li class="form-line" data-type="control_widget" id="id_31">
        <label class="form-label form-label-left form-label-auto" id="label_31" for="input_31"> Upload Your Artwork or Logo </label>
        <div id="cid_31" class="form-input">
          <div style="width:100%; text-align:Left;">
            <iframe onload="widgetFrameLoaded(31)" frameborder="0" scrolling="no" class="custom-field-frame" id="customFieldFrame_31" src="" style="border:none;width:640px; height: 120px;">
            </iframe>
            <div>
              <input id="input_31" class="form-hidden form-widget" type="hidden" name="q31_uploadYour31" value="">
            </div>
            <script>
            setTimeout(function()
{
  document.getElementById("customFieldFrame_31").src = "http://widgets.jotform.io/imagepreview/?buttontitle=BROWSE&customcss=%3Cempty%3E&qid=31&ref=" + encodeURIComponent(window.location.protocol + "//" + window.location.host);
}, 5);
var _JCFClientID = 31
            </script>
          </div>
        </div>
      </li>
      <li class="form-line" data-type="control_widget" id="id_32">
        <div id="cid_32" class="form-input">
          <div style="width:100%; text-align:Left;">
            <iframe onload="widgetFrameLoaded(32)" frameborder="0" scrolling="no" class="custom-field-frame" id="customFieldFrame_32" src="" style="border:none;width:640px; height: 120px;">
            </iframe>
            <div>
              <input id="input_32" class="form-hidden form-widget" type="hidden" name="q32_clickTo32" value="">
            </div>
            <script>
            setTimeout(function()
{
  document.getElementById("customFieldFrame_32").src = "http://widgets.jotform.io/textillate/?effect=flash&qid=32&ref=" + encodeURIComponent(window.location.protocol + "//" + window.location.host);
}, 5);
var _JCFClientID = 32
            </script>
          </div>
        </div>
      </li>
      <li class="form-line" data-type="control_textarea" id="id_19">
        <label class="form-label form-label-left form-label-auto" id="label_19" for="input_19"> Please explain your ideas here. </label>
        <div id="cid_19" class="form-input">
          <textarea id="input_19" class="form-textarea" name="q19_pleaseExplain" cols="40" rows="6"></textarea>
        </div>
      </li>
      <li class="form-line" data-type="control_datetime" id="id_20">
        <label class="form-label form-label-left form-label-auto" id="label_20" for="input_20"> DATE NEEDED BY </label>
        <div id="cid_20" class="form-input">
          <span class="form-sub-label-container">
            <input class="form-textbox validate[disallowPast]" id="month_20" name="q20_20[month]" type="tel" size="2" maxlength="2" value="09" />
            <span class="date-separate">
               -
            </span>
            <label class="form-sub-label" for="month_20" id="sublabel_month"> Month </label>
          </span>
          <span class="form-sub-label-container">
            <input class="form-textbox validate[disallowPast]" id="day_20" name="q20_20[day]" type="tel" size="2" maxlength="2" value="11" />
            <span class="date-separate">
               -
            </span>
            <label class="form-sub-label" for="day_20" id="sublabel_day"> Day </label>
          </span>
          <span class="form-sub-label-container">
            <input class="form-textbox validate[disallowPast]" id="year_20" name="q20_20[year]" type="tel" size="4" maxlength="4" value="2014" />
            <label class="form-sub-label" for="year_20" id="sublabel_year"> Year </label>
          </span>
          <span class="form-sub-label-container">
            <img class="showAutoCalendar" alt="Pick a Date" id="input_20_pick" src="http://max.jotfor.ms/images/calendar.png" align="absmiddle" />
            <label class="form-sub-label" for="input_20_pick">
              <div>
                   
              </div>
            </label>
          </span>
        </div>
      </li>
      <li class="form-line" data-type="control_button" id="id_2">
        <div id="cid_2" class="form-input-wide">
          <div style="margin-left:156px" class="form-buttons-wrapper">
            <button id="input_2" type="submit" class="form-submit-button form-submit-button-push_red">
              SUBMIT
            </button>
          </div>
        </div>
      </li>
      <li id="cid_30" class="form-input-wide" data-type="control_head">
        <div class="form-header-group">
          <div class="header-text httal htvam">
            <h2 id="header_30" class="form-header">
              Get Some Ideas from some of our custom designs below.
            </h2>
          </div>
        </div>
      </li>
      <li class="form-line" data-type="control_text" id="id_29">
        <div id="cid_29" class="form-input-wide">
          <div id="text_29" class="form-html">
            <p><iframe  width="480" height="360" src="http://s395.photobucket.com/user/jasmynnmorgan/embed/slideshow/Bling%20Samples" alt="" /></iframe></p>
          </div>
        </div>
      </li>
      <li style="display:none">
        Should be Empty:
        <input type="text" name="website" value="" />
      </li>
    </ul>
  </div>
  <input type="hidden" id="simple_spc" name="simple_spc" value="22101528081138" />
  <script type="text/javascript">
  document.getElementById("si" + "mple" + "_spc").value = "22101528081138-22101528081138";
  </script>
  <script src="http://jotform.us/js/widgetResizer.js?REV=3.2.3591" type="text/javascript"></script>
</form>

Share this post


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

I needed to add a simple contact form to one CMS page and I had to put together pieces from different post. Mainly from here (thank you): http://www.prestashop.com/forums/topic/246845-solved-custom-form/

 

I was surprised to not find more strainght forward information, so I am going to summarize here what I did in case it helps someone else in the future. First you need to extend your TinyMCE, follow the link provided by vekia above.

 

I inserted the form in the HTML editor of my CMS page:

<form action="" method="post" autocomplete="off">
<div><label>NAME</label>
<div><input style="width: 220px; height: 28px;" name="name" type="text" /></div>
</div>
<br />
<div><label>BEST CONTACT</label>
<div><input style="width: 220px; height: 28px;" name="email" type="text" />
<div><spam style="font-style: italic;">(email, phone or both)</spam></div>
</div>
</div>
<br />
<div class="quickformsubject"><label>SUBJECT</label>
<div><input style="width: 220px; height: 28px;" name="subject" type="text" /></div>
</div>
<div><label>YOUR MESSAGE</label>
<div><textarea style="width: 340px; height: 100px;" name="message" rows="6" cols="25"></textarea></div>
</div>
<br />
<div><input class="button" name="quickcontact" value="Contact me" type="submit" /></div>
</form>

The SUBJECT field is a trap for spambots, it is hidden for human users, therefore it should be always empty; if robots fill it out the form dies (more info here: http://riserinteractive.com/stop-form-spam-without-captcha-or-quizzes/)

Add the following to your CSS to hide the trap field:

.quickformsubject {
    display: none;       
}

Last, I added this to my CmsController.php file. It goes inside the funtion function init(), I put it at the end, right after "header('Status: 404 Not Found'); }"

if (isset($_POST['quickcontact'])){
            if ( $_POST['subject'] != '' ) {
                die("ERROR");
            } else {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $formcontent="From: $name \n Email: $email \n Message: $message";
        $recipient = "email@yourdomain.com";
        $subject = "Quick Contact Form";
         $mailheader = "From: $email \r\n";
        mail($recipient, $subject, $formcontent, $mailheader) or die("Error");
        header( 'Location: http://yourdomain.com/store/en/content/16-thank-you' ) ;
            }
        }

The form will redirect the user to a thank you page or any other page you select, it will not sent a confirmation email to the user. It worked for me in PS 1.5.6.1

 

Good luck,

You mans global.css ? where in CSS file could you please explain?

Share this post


Link to post
Share on other sites
  • 1 month later...

Hi vekia

 

In CMS Page there is an options for creating tables for making rows , column but I doesn't works in 1.6.0.8

 

Does we need to extend tinymce to full version for inserting a simple table format in CMS.

 

Can u pls help me with this

Share this post


Link to post
Share on other sites

Also how do we apply different colour background to different column using a table format.

 

Is this also functions which doesn't work with 1.6.0.8 Multistore.

For this also we need to first extend TinyMce first.

 

Pls let me as simple HTML editor is CMS doesn't work.

Share this post


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

I needed to add a simple contact form to one CMS page and I had to put together pieces from different post. Mainly from here (thank you): http://www.prestashop.com/forums/topic/246845-solved-custom-form/

 

I was surprised to not find more strainght forward information, so I am going to summarize here what I did in case it helps someone else in the future. First you need to extend your TinyMCE, follow the link provided by vekia above.

 

I inserted the form in the HTML editor of my CMS page:

<form action="" method="post" autocomplete="off">
<div><label>NAME</label>
<div><input style="width: 220px; height: 28px;" name="name" type="text" /></div>
</div>
<br />
<div><label>BEST CONTACT</label>
<div><input style="width: 220px; height: 28px;" name="email" type="text" />
<div><spam style="font-style: italic;">(email, phone or both)</spam></div>
</div>
</div>
<br />
<div class="quickformsubject"><label>SUBJECT</label>
<div><input style="width: 220px; height: 28px;" name="subject" type="text" /></div>
</div>
<div><label>YOUR MESSAGE</label>
<div><textarea style="width: 340px; height: 100px;" name="message" rows="6" cols="25"></textarea></div>
</div>
<br />
<div><input class="button" name="quickcontact" value="Contact me" type="submit" /></div>
</form>

The SUBJECT field is a trap for spambots, it is hidden for human users, therefore it should be always empty; if robots fill it out the form dies (more info here: http://riserinteractive.com/stop-form-spam-without-captcha-or-quizzes/)

Add the following to your CSS to hide the trap field:

.quickformsubject {
    display: none;       
}

Last, I added this to my CmsController.php file. It goes inside the funtion function init(), I put it at the end, right after "header('Status: 404 Not Found'); }"

if (isset($_POST['quickcontact'])){
            if ( $_POST['subject'] != '' ) {
                die("ERROR");
            } else {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $formcontent="From: $name \n Email: $email \n Message: $message";
        $recipient = "email@yourdomain.com";
        $subject = "Quick Contact Form";
         $mailheader = "From: $email \r\n";
        mail($recipient, $subject, $formcontent, $mailheader) or die("Error");
        header( 'Location: http://yourdomain.com/store/en/content/16-thank-you' ) ;
            }
        }

The form will redirect the user to a thank you page or any other page you select, it will not sent a confirmation email to the user. It worked for me in PS 1.5.6.1

 

Good luck,

 

Is it possible to make some fields mandatory and to validate email using this method?

 

tnx!

 

Nevermind, I've done it myself :)

Edited by lupillus (see edit history)

Share this post


Link to post
Share on other sites

 

may i know how you achieved it?

Of course Vekia :)

 

Here it is:

 

 

if (isset($_POST['quickcontact'])){
		
		$name = $_POST["name"];
		$email = $_POST["email"];
		$message = $_POST["message"];
		
		if ( $_POST['subject'] != '' ) {
			$this->errors[] = Tools::displayError('An error occurred while sending the message.');
		} else if ($name =='' || $email =='' || $message ==''){
			$this->errors[] = Tools::displayError('Please fill all required fields');
		} else if (!filter_var($email, FILTER_VALIDATE_EMAIL)){
			$this->errors[] = Tools::displayError('Invalid email format');
		} else{
			$formcontent="From: $name \n Email: $email \n Message: $message";
			$recipient = Configuration::get('PS_SHOP_EMAIL');
			$subject = "Quick Contact Form";
			$mailheader = "From: $email \r\n";
			mail($recipient, $subject, $formcontent, $mailheader) or die("Error");
			header( 'Location: http://www.google.com' ) ;
            }
        }

 

But I have another problem with this. When I submit form it is displaying errors, but emptying all values from fileds. Maybe my solution isn't good :) And there is no way to put php into cms page via admin

 

UPDATE:

And I found solution for that also :) using jquery. If anyone is interested here is the solution.

if (isset($_POST['quickcontact'])){
		
		$name = $_POST["name"];
		$email = $_POST["email"];
		$message = $_POST["message"];
		
		echo '<script>';
		print "var name = '$name'; var message = '$message'; var email = '$message';";
		echo '</script>';
		
		if ( $_POST['subject'] != '' ) {
			$this->errors[] = Tools::displayError('An error occurred while sending the message.');
		} else if ($name =='' || $email =='' || $message ==''){

			$this->errors[] = Tools::displayError('Please fill all required fields');
		} else if (!filter_var($email, FILTER_VALIDATE_EMAIL)){
			$this->errors[] = Tools::displayError('Invalid email format');
		} else{
			$formcontent="From: $name \n Email: $email \n Message: $message";
			$recipient = Configuration::get('PS_SHOP_EMAIL');
			$subject = "Quick Contact Form";
			$mailheader = "From: $email \r\n";
			mail($recipient, $subject, $formcontent, $mailheader) or die("Error");
			header( 'Location: http://www.google.com' ) ;
            }
        }

And in CMS page inserted the jquery code

<script type="text/javascript">
// <![CDATA[
$(document).ready(function (){
   $('input[name=name]').val(name);
   $('textarea[name=message]').val(message);
   $('input[name=email]').val(email);
   });
// ]]>
</script>

Please Vekia tell me if this is OK way to do it :)

Edited by lupillus (see edit history)

Share this post


Link to post
Share on other sites
  • 11 months later...
Hello Vekia,

I did as advised under: 

And I am getting a message:Parse error syntex error unexpected 'function' (T_FUNCTION) in ................\CmsController.php on line 51 

 

create form like

<form action="" method="post">

... FIELDS

... FIELDS

... FIELDS

<input type="submit" name="customcontact" value="submit" />

</form>

then in controllers/front/CmsController.php file, in init() function add code like this:

if (isset($_POST['customcontact'])){

mail function here

}

 

PLease advice Many a thanks

Share this post


Link to post
Share on other sites
  • 1 year later...

I needed to add a simple contact form to one CMS page and I had to put together pieces from different post. Mainly from here (thank you): http://www.prestashop.com/forums/topic/246845-solved-custom-form/

 

I was surprised to not find more strainght forward information, so I am going to summarize here what I did in case it helps someone else in the future. First you need to extend your TinyMCE, follow the link provided by vekia above.

 

I inserted the form in the HTML editor of my CMS page:

<form action="" method="post" autocomplete="off">
<div><label>NAME</label>
<div><input style="width: 220px; height: 28px;" name="name" type="text" /></div>
</div>
<br />
<div><label>BEST CONTACT</label>
<div><input style="width: 220px; height: 28px;" name="email" type="text" />
<div><spam style="font-style: italic;">(email, phone or both)</spam></div>
</div>
</div>
<br />
<div class="quickformsubject"><label>SUBJECT</label>
<div><input style="width: 220px; height: 28px;" name="subject" type="text" /></div>
</div>
<div><label>YOUR MESSAGE</label>
<div><textarea style="width: 340px; height: 100px;" name="message" rows="6" cols="25"></textarea></div>
</div>
<br />
<div><input class="button" name="quickcontact" value="Contact me" type="submit" /></div>
</form>

The SUBJECT field is a trap for spambots, it is hidden for human users, therefore it should be always empty; if robots fill it out the form dies (more info here: http://riserinteractive.com/stop-form-spam-without-captcha-or-quizzes/)

Add the following to your CSS to hide the trap field:

.quickformsubject {
    display: none;       
}

Last, I added this to my CmsController.php file. It goes inside the funtion function init(), I put it at the end, right after "header('Status: 404 Not Found'); }"

if (isset($_POST['quickcontact'])){
            if ( $_POST['subject'] != '' ) {
                die("ERROR");
            } else {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $formcontent="From: $name \n Email: $email \n Message: $message";
        $recipient = "email@yourdomain.com";
        $subject = "Quick Contact Form";
         $mailheader = "From: $email \r\n";
        mail($recipient, $subject, $formcontent, $mailheader) or die("Error");
        header( 'Location: http://yourdomain.com/store/en/content/16-thank-you' ) ;
            }
        }

The form will redirect the user to a thank you page or any other page you select, it will not sent a confirmation email to the user. It worked for me in PS 1.5.6.1

 

Good luck,

Hello Pietro,

 

I used your contact form and code added to cmcontroller.php and it works very well (thank you!)

But I need to know if I want to add others text fields or radio button selection  how can I do that in the cmscontroller.php file so that when someone sens me email I recieve all the informations compiled in the contact form?

 

thank you in advance

Share this post


Link to post
Share on other sites
  • 3 months later...
On 1/26/2015 at 9:39 PM, TFPtMaster said:

Hello guys

 

The submit button does not work for me. Any help?

 

On 8/18/2017 at 10:08 PM, eraser80 said:

Hello Pietro,

 

I used your contact form and code added to cmcontroller.php and it works very well (thank you!)

But I need to know if I want to add others text fields or radio button selection  how can I do that in the cmscontroller.php file so that when someone sens me email I recieve all the informations compiled in the contact form?

 

thank you in advance

 

Share this post


Link to post
Share on other sites
  • 5 months later...
On 28/3/2014 at 8:40 AM, pietro said:

I needed to add a simple contact form to one CMS page and I had to put together pieces from different post. Mainly from here (thank you): http://www.prestashop.com/forums/topic/246845-solved-custom-form/

 

I was surprised to not find more strainght forward information, so I am going to summarize here what I did in case it helps someone else in the future. First you need to extend your TinyMCE, follow the link provided by vekia above.

 

I inserted the form in the HTML editor of my CMS page:


<form action="" method="post" autocomplete="off">
<div><label>NAME</label>
<div><input style="width: 220px; height: 28px;" name="name" type="text" /></div>
</div>
<br />
<div><label>BEST CONTACT</label>
<div><input style="width: 220px; height: 28px;" name="email" type="text" />
<div><spam style="font-style: italic;">(email, phone or both)</spam></div>
</div>
</div>
<br />
<div class="quickformsubject"><label>SUBJECT</label>
<div><input style="width: 220px; height: 28px;" name="subject" type="text" /></div>
</div>
<div><label>YOUR MESSAGE</label>
<div><textarea style="width: 340px; height: 100px;" name="message" rows="6" cols="25"></textarea></div>
</div>
<br />
<div><input class="button" name="quickcontact" value="Contact me" type="submit" /></div>
</form>

The SUBJECT field is a trap for spambots, it is hidden for human users, therefore it should be always empty; if robots fill it out the form dies (more info here: http://riserinteractive.com/stop-form-spam-without-captcha-or-quizzes/)

Add the following to your CSS to hide the trap field:


.quickformsubject {
    display: none;       
}

Last, I added this to my CmsController.php file. It goes inside the funtion function init(), I put it at the end, right after "header('Status: 404 Not Found'); }"


if (isset($_POST['quickcontact'])){
            if ( $_POST['subject'] != '' ) {
                die("ERROR");
            } else {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $formcontent="From: $name \n Email: $email \n Message: $message";
        $recipient = "email@yourdomain.com";
        $subject = "Quick Contact Form";
         $mailheader = "From: $email \r\n";
        mail($recipient, $subject, $formcontent, $mailheader) or die("Error");
        header( 'Location: http://yourdomain.com/store/en/content/16-thank-you' ) ;
            }
        }

The form will redirect the user to a thank you page or any other page you select, it will not sent a confirmation email to the user. It worked for me in PS 1.5.6.1

 

Good luck,

 

 

 

Hello when I press te submit button it gives me an error

Has anyone encoutered a problem like this?

 

 

Share this post


Link to post
Share on other sites
  • 2 years later...
On 5/23/2018 at 3:44 AM, annapad24 said:

Hello when I press te submit button it gives me an error

Has anyone encoutered a problem like this?

 

 

You have to give more details about the error (not this time, but always):
what error message says
where it appears
what url is durring error message
what system logs says
and etc.

Share this post


Link to post
Share on other sites
On 3/28/2014 at 8:40 AM, pietro said:

Last, I added this to my CmsController.php file. It goes inside the funtion function init(), I put it at the end, right after "header('Status: 404 Not Found'); }"


if (isset($_POST['quickcontact'])){
            if ( $_POST['subject'] != '' ) {
                die("ERROR");
            } else {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $formcontent="From: $name \n Email: $email \n Message: $message";
        $recipient = "email@yourdomain.com";
        $subject = "Quick Contact Form";
         $mailheader = "From: $email \r\n";
        mail($recipient, $subject, $formcontent, $mailheader) or die("Error");
        header( 'Location: http://yourdomain.com/store/en/content/16-thank-you' ) ;
            }
        }

 

Please do not encourage editing of core files.

Create Override - in folder override/controllers/front/ create a file CmsController.

In it insert this:

class CmsController extends CmsControllerCore
{
    public function initContent(){
        parent::initContent(); // include everything what is already in core file (initContent function/method).
        if(Tools::getValue('quickcontact')){
            if ( $_POST['subject'] != '' ) {
                die("ERROR");
            } else {
              $name = $_POST['name'];
              $email = $_POST['email'];
              $message = $_POST['message'];
              $formcontent="From: $name \n Email: $email \n Message: $message";
              $recipient = "email@yourdomain.com";
              $subject = "Quick Contact Form";
               $mailheader = "From: $email \r\n";
              mail($recipient, $subject, $formcontent, $mailheader) or die("Error");
              header( 'Location: http://yourdomain.com/store/en/content/16-thank-you' ) ;
            }
        }

    }
}

In this case no updates of Prestashop core files are scared to You anymore ;)

Edited by Inter Svetainė
fixed path to FTP to add class (see edit history)

Share this post


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

thanks for your help guys , The solution of creating the form into cms.tpl and adding php code into cmscontroller.php worked fine for me , i recive an email but i recive it in spam folder,  and I also want to know how can i add into cmscontroller.php multi file upload for the form with (extension step,stl,png,jpeg...for 3 dimensions use)  , add select options and the checkbox , what should i add as a php code to recieve all those information by mail 

Capture.PNG

1.PNG

2.PNG

4.PNG

Share this post


Link to post
Share on other sites

As I understand 3 things You need (this is for 1.6):

  • mail goes to spam folder. Can't help much. Make sure You are sending mails not with php function but with separate mail server. Insert SMTP server details.
    Go to Admin > advanced settings > Mail
    Something like this https://domain.com/adminFolder/index.php?controller=AdminEmails
  • To add more info into email You can simply gather info from $_POST['matiere'] and add it to the message value something like this
    $message = "Message: " . $_POST['message'] . ", Matiere: " . $_POST['matiere'];

    So in this case Your message will contain needed data. Now You are assigning value from $_POST to variable $matiere, but You don't use it anywhere.

  • I offer You to use not emails to get request from clients. I offer to use ContactController and use class CustomerMessage. So whenever client will fill form and submit You will see it in Clients > Client messages. Something like here https://domain.com/adminFolder/index.php?controller=AdminCustomerThreads
    And if You will override ContactController ar edit core file adding something like this:
     

    for($i=1;$i<4;$i++)
    {
        if (isset(${'file_attachment' . $i}['rename']) && !empty(${'file_attachment' . $i}['rename']) && rename(${'file_attachment' . $i}['tmp_name'], _PS_UPLOAD_DIR_ . basename(${'file_attachment' . $i}['rename'])))
        {
            $cm = new CustomerMessage();
            $cm->file_name = ${'file_attachment' . $i}['rename'];
            @chmod(_PS_UPLOAD_DIR_ . basename(${'file_attachment'.$i}['rename']), 0664);
            $cm->id_customer_thread = $ct->id;
            $cm->message = 'File' . $i;
            $cm->ip_address = (int)ip2long(Tools::getRemoteAddr());
            $cm->user_agent = $_SERVER['HTTP_USER_AGENT'];
            if (!$cm->add())
            {
                $this->errors[] = Tools::displayError('An error occurred while sending/adding the message to client.');
            }
        }
    }

    As You see I hard-coded now for You to add 4 images.
    Lader on in "(!count($this->errors))" { add something like this to validate and assign

    $var_list = array(
      '{order_name}' => '-',
      '{attached_file}' => '-',
      '{attached_file1}' => '-',
      '{attached_file2}' => '-',
      '{attached_file3}' => '-',
      '{message}' => Tools::nl2br(stripslashes('Main material : '.Tools::getValue('main_material').', Quantity :'.Tools::getValue('quantity') .'| Message : ' .$message)),
      '{email}' =>  $from,
      '{product_name}' => '',
    );
    
    if (isset($file_attachment['name'])) {
    	$var_list['{attached_file}'] = $file_attachment['name'];
    }
    for($i=1;$i<4;$i++) {
    	if (isset(${'file_attachment' . $i}['name'])) {
        	$var_list['{attached_file'.$i.'}'] = ${'file_attachment' . $i}['name'];
    	}
    }


    I hope it will help to main get idea.

  • Thanks 1

Share this post


Link to post
Share on other sites
15 minutes ago, Inter Svetainė said:

As I understand 3 things You need (this is for 1.6):

  • mail goes to spam folder. Can't help much. Make sure You are sending mails not with php function but with separate mail server. Insert SMTP server details.
    Go to Admin > advanced settings > Mail
    Something like this https://domain.com/adminFolder/index.php?controller=AdminEmails
  • To add more info into email You can simply gather info from $_POST['matiere'] and add it to the message value something like this
    
    $message = "Message: " . $_POST['message'] . ", Matiere: " . $_POST['matiere'];

    So in this case Your message will contain needed data. Now You are assigning value from $_POST to variable $matiere, but You don't use it anywhere.

  • I offer You to use not emails to get request from clients. I offer to use ContactController and use class CustomerMessage. So whenever client will fill form and submit You will see it in Clients > Client messages. Something like here https://domain.com/adminFolder/index.php?controller=AdminCustomerThreads
    And if You will override ContactController ar edit core file adding something like this:
     

    
    for($i=1;$i<4;$i++)
    {
        if (isset(${'file_attachment' . $i}['rename']) && !empty(${'file_attachment' . $i}['rename']) && rename(${'file_attachment' . $i}['tmp_name'], _PS_UPLOAD_DIR_ . basename(${'file_attachment' . $i}['rename'])))
        {
            $cm = new CustomerMessage();
            $cm->file_name = ${'file_attachment' . $i}['rename'];
            @chmod(_PS_UPLOAD_DIR_ . basename(${'file_attachment'.$i}['rename']), 0664);
            $cm->id_customer_thread = $ct->id;
            $cm->message = 'File' . $i;
            $cm->ip_address = (int)ip2long(Tools::getRemoteAddr());
            $cm->user_agent = $_SERVER['HTTP_USER_AGENT'];
            if (!$cm->add())
            {
                $this->errors[] = Tools::displayError('An error occurred while sending/adding the message to client.');
            }
        }
    }

    As You see I hard-coded now for You to add 4 images.
    Lader on in "(!count($this->errors))" { add something like this to validate and assign

    
    $var_list = array(
      '{order_name}' => '-',
      '{attached_file}' => '-',
      '{attached_file1}' => '-',
      '{attached_file2}' => '-',
      '{attached_file3}' => '-',
      '{message}' => Tools::nl2br(stripslashes('Main material : '.Tools::getValue('main_material').', Quantity :'.Tools::getValue('quantity') .'| Message : ' .$message)),
      '{email}' =>  $from,
      '{product_name}' => '',
    );
    
    if (isset($file_attachment['name'])) {
    	$var_list['{attached_file}'] = $file_attachment['name'];
    }
    for($i=1;$i<4;$i++) {
    	if (isset(${'file_attachment' . $i}['name'])) {
        	$var_list['{attached_file'.$i.'}'] = ${'file_attachment' . $i}['name'];
    	}
    }


    I hope it will help to main get idea.

thanks for this kind of solution , i use prestashop 1.7.7  and I am going to try it for now and i ll feed back , I am so gratefull for your kind of help , for the moment i inserted this php code into my cmscontroller.php , and now every file uploaded into the form goes to www/upload directory , now what I want to do is to send this uploaded file with the fields in the form to an email adress ,    I am gonna use ur solution and test , and if you have any idea about how to send the email with the fields of the form and the attached file i ll be so grateful

upload.PNG

Share this post


Link to post
Share on other sites
1 hour ago, waterman455 said:

thanks for this kind of solution , i use prestashop 1.7.7  and I am going to try it for now and i ll feed back , I am so gratefull for your kind of help , for the moment i inserted this php code into my cmscontroller.php , and now every file uploaded into the form goes to www/upload directory , now what I want to do is to send this uploaded file with the fields in the form to an email adress ,    I am gonna use ur solution and test , and if you have any idea about how to send the email with the fields of the form and the attached file i ll be so grateful

upload.PNG

Your welcome. Glad to help.

I'm sorry it's hard to understand what Your goal is. You write "send this uploaded file with fields". I guess You mean with form inputs.
Please refer to Prestashop 1.7 class Mail, where You will find method send. You can use/call everywhere in php file send function https://github.com/PrestaShop/PrestaShop/blob/0e493eaa715fc16ac8de4e924bc691cfaa78f6f6/classes/Mail.php#L132

Mail::send {
	arguments with trailing comma
}

Don't hesitate to surf more about any method needed to attach image to mail. Hover with mouse on $fileAttachmentScreenshot_74.thumb.png.434fe719ad54ad9bfe8ccc71e9d43d40.pngScreenshot_74.thumb.png.434fe719ad54ad9bfe8ccc71e9d43d40.pngScreenshot_74.thumb.png.434fe719ad54ad9bfe8ccc71e9d43d40.pngt

  • Like 1

Share this post


Link to post
Share on other sites

Don't try to do everything at once.

Please firstly try to send mail with one attachment from server (already existing file in Your FTP).
Then with one file with INPUT type file.
Then with many files send mail.
I'll be here to help You.
p.s. please always attach code as code (in toolbar search for <> symbols), not as screenshot.

  • Like 1

Share this post


Link to post
Share on other sites

Hello Inter Svetainé , thanks a lot for your help and feed back , I really appreciate it , I was fixing the smtp email configuration for local host , I added the upload file path so when I upload a file with the form I get it into my www\uploads directory ,  Now I am working on sending this uploaded file with other input fields from the form to an email adress with the mail::send that you told me about it ,  so I added this code  :    < 

    public function initContent()

    

        {

            if (isset($_POST['customcontact'])){

 

                $file = $_FILES['fileUpload'];

                $allowed = array('txt', 'rtf', 'doc', 'docx', 'pdf', 'png', 'jpeg', 'gif', 'jpg', 'bmp', 'stl', 'obj', 'step', 'igs');

                $extension = pathinfo($file['name'], PATHINFO_EXTENSION);

                if ( file_exists($file['tmp_name']) && in_array($extension, $allowed) )

                {

                $filename = uniqid()."-".basename($file['name']);

                $filename = str_replace(' ', '-', $filename);

                $filename = strtolower($filename);

                $filename = filter_var($filename, FILTER_SANITIZE_STRING);

                

                $file['name'] = $filename;

                

                $uploader = new UploaderCore();

                $uploader->upload($file);

                


 

                $name = $_POST['name'];

 

                $largeur = $_POST['largeur'];

                $hauteur = $_POST['hauteur'];

                $profondeur = $_POST['profondeur'];

 

                $email = $_POST['email'];

                

                $message = $_POST['message'];

    

                $matiere = $_POST['matiere'];

 

                $plateaux = $_POST["plateaux"];

 

                $mailheader = "From: $email \r\n";

 

                $recipient = "zied.haddan@gmail.com";

 

                $formcontent="From: $email \n Message: $message \n Nom: $name \n Matiere: $matiere \n Plateaux: $plateaux \n Largeur: $largeur \n Hauteur: $hauteur \n Profondeur: $profondeur ";

 

                $subject = "Sur Demande";

 

                Mail::send(

                    $this->context->language->id,

                    'cms_controller_form',

                    $recipient,

                    $subject,

                    $formcontent,

                    $mailheader

                ); >

unluckly I get an error  Error: parameter "to" is corrupted ,    I also created an added cms_controller_form.txt and cms_controller.html into www\mails\fr directory as an  mail template ,  Now I dont know how to deal with this error Error: parameter "to" is corrupted , thanks a lot for your help and kindness

 

Share this post


Link to post
Share on other sites
1 hour ago, waterman455 said:

Hello Inter Svetainé , thanks a lot for your help and feed back , I really appreciate it , I was fixing the smtp email configuration for local host , I added the upload file path so when I upload a file with the form I get it into my www\uploads directory ,  Now I am working on sending this uploaded file with other input fields from the form to an email adress with the mail::send that you told me about it ,  so I added this code  :    < 

    public function initContent()

    

        {

            if (isset($_POST['customcontact'])){

 

                $file = $_FILES['fileUpload'];

                $allowed = array('txt', 'rtf', 'doc', 'docx', 'pdf', 'png', 'jpeg', 'gif', 'jpg', 'bmp', 'stl', 'obj', 'step', 'igs');

                $extension = pathinfo($file['name'], PATHINFO_EXTENSION);

                if ( file_exists($file['tmp_name']) && in_array($extension, $allowed) )

                {

                $filename = uniqid()."-".basename($file['name']);

                $filename = str_replace(' ', '-', $filename);

                $filename = strtolower($filename);

                $filename = filter_var($filename, FILTER_SANITIZE_STRING);

                

                $file['name'] = $filename;

                

                $uploader = new UploaderCore();

                $uploader->upload($file);

                


 

                $name = $_POST['name'];

 

                $largeur = $_POST['largeur'];

                $hauteur = $_POST['hauteur'];

                $profondeur = $_POST['profondeur'];

 

                $email = $_POST['email'];

                

                $message = $_POST['message'];

    

                $matiere = $_POST['matiere'];

 

                $plateaux = $_POST["plateaux"];

 

                $mailheader = "From: $email \r\n";

 

                $recipient = "zied.haddan@gmail.com";

 

                $formcontent="From: $email \n Message: $message \n Nom: $name \n Matiere: $matiere \n Plateaux: $plateaux \n Largeur: $largeur \n Hauteur: $hauteur \n Profondeur: $profondeur ";

 

                $subject = "Sur Demande";

 

                Mail::send(

                    $this->context->language->id,

                    'cms_controller_form',

                    $recipient,

                    $subject,

                    $formcontent,

                    $mailheader

                ); >

unluckly I get an error  Error: parameter "to" is corrupted ,    I also created an added cms_controller_form.txt and cms_controller.html into www\mails\fr directory as an  mail template ,  Now I dont know how to deal with this error Error: parameter "to" is corrupted , thanks a lot for your help and kindness

 

No prob. Glad to help.

I see the problem. Error says parameter "to" is wrong.
The reason is that parameter "TO" is the fifth in parameters list.

Let's look at the class Mail and method send parameters list

public static function send(
        $idLang,
        $template,
        $subject,
        $templateVars,
        $to,
        $toName = null,
        $from = null,
        $fromName = null,
        $fileAttachment = null,
        $mode_smtp = null,
        $templatePath = _PS_MAIL_DIR_,
        $die = false,
        $idShop = null,
        $bcc = null,
        $replyTo = null,
        $replyToName = null
    ) {

From the code You see that $to is the fifth, but in Your code TO is the third

Mail::send(

  $this->context->language->id,

  'cms_controller_form',

  $recipient,

  $subject,

  $formcontent,

  $mailheader

); > 

You have to/need/must follow parameters order.
Please try this code:

Mail::send(
  $this->context->language->id,
  'cms_controller_form',
  Mail::l('Customer contact'),
  array(
  '{name}' => $name,
  '{largeur}' => $largeur),
  $recipient,
  $name
); > 

p.s. don't use plain text in code. Always write text with translatable option.
inspite of this

$subject = "Sur Demande";

Better use this

$subject = Mail::l('Sur Demande');

cause then You could translate this phrase into another language and switching languages in Your website users will see their language text ;)

Please let me know will You succeed with it.

  • Like 1

Share this post


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

Hello @Inter Svetainė  , thanks for your great help , I fixed everything in my localhost and I configured the smtp for email transfert and i created email template and it works , thanks a lot , hope if i move this to prod I dont get any problem with my hoster

Share this post


Link to post
Share on other sites
On 3/1/2021 at 12:25 PM, waterman455 said:

Hello @Inter Svetainė  , thanks for your great help , I fixed everything in my localhost and I configured the smtp for email transfert and i created email template and it works , thanks a lot , hope if i move this to prod I dont get any problem with my hoster

Hey, @waterman455. Glad to help 🤨
Please enable debug mode for few minutes after You will upload all changes to PROD server. Why? To see all errors or warnings. Cause sometimes some code without debug mode does no harm (works everything fine) but in log file are inserted so many lines, that sometimes log file gets 1gb size just in a few days.

I'll keep watching/subscribing this post just in case You ever need more help about this.

  • Thanks 1

Share this post


Link to post
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...

Important Information

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