Jump to content

[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)
  • Like 1
Link to comment
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

Link to comment
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

Link to comment
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

  • Like 1
  • Thanks 1
Link to comment
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 6
Link to comment
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

Link to comment
Share on other sites

  • 2 months later...
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. 

Link to comment
Share on other sites

  • 1 month later...

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

Link to comment
Share on other sites

  • 3 weeks later...
  • 5 weeks later...
  • 4 weeks later...
  • 2 weeks later...
  • 3 weeks later...
  • 1 month later...
  • 1 month later...
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

Link to comment
Share on other sites

  • 4 weeks later...
  • 11 months later...
  • 4 weeks later...
1 hour ago, yousaf traders said:

Hello

My name is saboor and i need help from modrator.Right know i am facing some problems on pristashop and its making headache for me.I am trying to Upgrade Pristashop but its giving Request time out by the server and i need some one who can guide me to the right path.

1 hour ago, yousaf traders said:

Hello

My name is saboor and i need help from modrator.Right know i am facing some problems on pristashop and its making headache for me.I am trying to Upgrade Pristashop but its giving Request time out by the server and i need some one who can guide me to the right path.

ss 1.PNG

Hello, i would suggest you to upgrade your hosting profile. It is a matter related to your hosting profile and hosting company.

 

Link to comment
Share on other sites

  • 8 months later...

Thanks,

I solved my same problem with this topic. 

 

      </div>

    </section>

    <footer class="form-footer text-xs-right">
      <input type="hidden" name="url" value=""/>
      <input type="hidden" name="token" value="{$token}">
   
      <input class="btn btn-primary" type="submit" name="submitMessage" value="{l s='Send' d='Shop.Theme.Actions'}">
    </footer>


  </form>
</section>

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...