Jump to content
alberto

[SOLVED]default Contact form gives "An error occurred while sending the message, please try again..."

Recommended Posts

Hi  to everybody, i just noted now that my contact form is not working,

it keeps saying "An error occurred while sending the message, please try again..."

 

INFO:

PS version 1.7.3.3

Info server Linux #36-Ubuntu SMP Wed Aug 15 16:00:05 UTC 2018 x86_64

Version server: Apache

Version PHP: 7.1.20

 

i thought it was a cloudflare problem, but then when i switched it off the error persisted.

 

I checked the file:  modules/contactform/contactform.php:

the error is in the sendMessage() function and specifically in this else statement:

elseif ($url !== ''
            || empty($serverToken)
            || $clientToken !== $serverToken
            || $clientTokenTTL < time()
        ) { /* error happen here */
            $this->context->controller->errors[] = $this->trans(
                'An error occurred while sending the message, please try again... ',
                [],
                'Modules.Contactform.Shop'
            );
            $this->createNewToken();
         }

 

i tried to print out the 4 variables but only $serverToken and $clientTokenTTL were printed.

 

What could be the problem?

I am NOT a prestashop developer, just another happy sometimes user.

 

thank you in advance!

Alberto

Edited by alberto (see edit history)

Share this post


Link to post
Share on other sites

Hello:

According to your information it seems that you are not receiving properly the params on the submit:

$url = Tools::getValue('url');
$clientToken = Tools::getValue('token');
        

Check in your browser developer console the request made when you click on Send message button and verify that parameters of the request are send successfully. If yes, in PHP try to print all $_POST and $_GET vars to check if "url" and "token" values are setted properly. If not, you should look in the HTML code if this vars exists in fact and have a valid value.

That´s the first step.

Good luck.

Regards

Share this post


Link to post
Share on other sites
36 minutes ago, Rolige said:

Hello:

According to your information it seems that you are not receiving properly the params on the submit:


$url = Tools::getValue('url');
$clientToken = Tools::getValue('token');
        

Check in your browser developer console the request made when you click on Send message button and verify that parameters of the request are send successfully. If yes, in PHP try to print all $_POST and $_GET vars to check if "url" and "token" values are setted properly. If not, you should look in the HTML code if this vars exists in fact and have a valid value.

That´s the first step.

Good luck.

Regards

In the console i just see:

 

  1. id_contact:
    2
  2. from:
    <email>
  3. message:
    test
  4. submitMessage:
    Send
I went through the contactform.tpl and i can see at the end there is:
 
<style>
          input[name=url] {
            display: none !important;
          }
        </style>
        <input type="text" name="url" value=""/>
        <input type="hidden" name="token" value="{$token}" />
        <button type="submit" name="submitMessage">
          {l s='Send' d='Modules.Contactform.Shop'}
        </button>

BUT

if i look at the html page thos two fields are not present... and also the structure seems to be different.. why?

 

This is all i have in the footer section of the contact form html page..

<input class="btn btn-primary" type="submit" name="submitMessage" value="Send">

 

Is that contactform.tpl being used or there is another one somewhere?

I tried to uninstall and reinstall it, no change

Share this post


Link to post
Share on other sites
2 hours ago, alberto said:

In the console i just see:

 

  1. id_contact:
    2
  2. from:
    <email>
  3. message:
    test
  4. submitMessage:
    Send
I went through the contactform.tpl and i can see at the end there is:
 

<style>
          input[name=url] {
            display: none !important;
          }
        </style>
        <input type="text" name="url" value=""/>
        <input type="hidden" name="token" value="{$token}" />
        <button type="submit" name="submitMessage">
          {l s='Send' d='Modules.Contactform.Shop'}
        </button>

BUT

if i look at the html page thos two fields are not present... and also the structure seems to be different.. why?

 

This is all i have in the footer section of the contact form html page..

<input class="btn btn-primary" type="submit" name="submitMessage" value="Send">

 

Is that contactform.tpl being used or there is another one somewhere?

I tried to uninstall and reinstall it, no change

You maybe have another TPL in your installed theme overriding the default one. Look for it on theme folder. According to your code params are there, but according to your HTML they are not, so you are probably looking on the wrong TPL file.

Regards

  • Thanks 1

Share this post


Link to post
Share on other sites
16 hours ago, Rolige said:

You maybe have another TPL in your installed theme overriding the default one. Look for it on theme folder. According to your code params are there, but according to your HTML they are not, so you are probably looking on the wrong TPL file.

Regards

SOLVED. Thanks!

 

there is another TPL file which is under "<theme folder>/modules/contactform/views/templates/widget/contactform.tpl"

 

i just added the two rows:

      <input type="hidden" name="url" value=""/>
      <input type="hidden" name="token" value="{$token}">

just before the submit button, and it works! 

 

The strange thing was that editing the first tpl file, i was able to see modifications.. infact i printed the variables by doing so.. but actually the file under the theme folder is also involved... i am confused by that, seems that it takes both files..

 

Thanks!

Edited by alberto (see edit history)
  • Thanks 4

Share this post


Link to post
Share on other sites
5 hours ago, alberto said:

SOLVED. Thanks!

 

there is another TPL file which is under "<theme folder>/modules/contactform/views/templates/widget/contactform.tpl"

 

i just added the two rows:

      <input type="hidden" name="url" value=""/>
      <input type="hidden" name="token" value="{$token}">

just before the submit button, and it works! 

 

The strange thing was that editing the first tpl file, i was able to see modifications.. infact i printed the variables by doing so.. but actually the file under the theme folder is also involved... i am confused by that, seems that it takes both files..

 

Thanks!

Please, mark question as solved ;) Regards

Share this post


Link to post
Share on other sites
On 10/26/2018 at 11:10 AM, alberto said:

SOLVED. Thanks!

 

there is another TPL file which is under "<theme folder>/modules/contactform/views/templates/widget/contactform.tpl"

 

i just added the two rows:

      <input type="hidden" name="url" value=""/>
      <input type="hidden" name="token" value="{$token}">

just before the submit button, and it works! 

 

The strange thing was that editing the first tpl file, i was able to see modifications.. infact i printed the variables by doing so.. but actually the file under the theme folder is also involved... i am confused by that, seems that it takes both files..

 

Thanks!

Hello for everybody, I've added this lines :

 

<input type="hidden" name="url" value=""/>
      <input type="hidden" name="token" value="{$token}">

and error message doesn't appear but it doesn't work because email never is recieved!. Any idea? I am stuck some days. 

Share this post


Link to post
Share on other sites

Hi!

Prestashop version: 1.6.x

Try this:

root > controllers > front > Contact.Controller.php

On line 56 aprox. comment out this lines as shown below: 

/*  } elseif ($url === false || !empty($url) || $saveContactKey != (Tools::getValue('contactKey'))) {
                $this->errors[] = Tools::displayError('An error occurred while sending the message.'); */

It WORKED for me after 1000 tries ... and I tried EVERYTHING!!! GOOD LUCK

Share this post


Link to post
Share on other sites
On 10/26/2018 at 4:10 PM, alberto said:

<input type="hidden" name="url" value=""/>
      <input type="hidden" name="token" value="{$token}">

nice, my contact form is working now.. thanks a lot

Share this post


Link to post
Share on other sites

Thank you your steps and some overrides helped me too

Share this post


Link to post
Share on other sites

hello, I have the same problem under prestashop 1.7.4.3 I do not know what to do someone can help me

 

Share this post


Link to post
Share on other sites

@solostyle can you provide me the link to you store? then I might figure it out what the problem is.

Share this post


Link to post
Share on other sites

prestashop 1.7.4.1 ...unfortunately it does not work.

 

here is the link: SITE

any suggestion or help?

Share this post


Link to post
Share on other sites
On 1/9/2019 at 11:48 AM, fernandido said:

Hello for everybody, I've added this lines :

 

<input type="hidden" name="url" value=""/>
      <input type="hidden" name="token" value="{$token}">

and error message doesn't appear but it doesn't work because email never is recieved!. Any idea? I am stuck some days. 

I have the same problem, because I don't see the error message anymore, but I still don't receive emails...

Can someone help me? thanks a lot

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

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