“#0 timeout-or-duplicate” error in VirtueMart

Do you see an error code like this “#0 timeout-or-duplicate” when sending messages from “Ask for Price” or “Ask a question about the product” VirtueMart forms? Then you’re on the right place.

#0 timeout-or-duplicate

#0-timeout-or-duplicate

This error message is actually from Recaptcha plugin, so it will appear only if we have Recaptcha enabled in the Virtuemart configuration, which is advisable because spammers will find you sooner or later.

It is important to mention that this happened only in Virtuemart. Joomla contact form and sending a test email from the Joomla Global configuration worked just fine. Actually, I also saw error message “Could not instantiate mail function”. I don’t recall anymore if that error showed in Joomla contact form or just in VirtueMart, but I fixed it simply by changing “Mailer” setting from “PHP Mail” to SMTP. After that I dind’t see this error message, but it still didn’t work from Virtuemart showing damn “#0 timeout-or-duplicate”.

After some investigation and experimenting I realized that the problem was that I had multiple captcha plugins enabled. So I had configuration like this:

My Joomla captcha plugins configuration

After disabling the second captcha plugin and leaving only the “Captcha – ReCaptcha” enabled sending of email started to work 🙂 It seems that VirtueMart is stupid enough to invoke each enabled captcha plugin, instead of only the one that is selected in the Joomla Global Configuration and that’s why we see this “duplicate” error.

#0 Empty solution not allowed

Then I wanted to see what would happen if I switch to “Invisible reCaptcha”. After that, sending email from Joomla contact form worked fine and it was cool that I don’t need to click “I am not a robot”. Unfortunately, it seems that Virtuemart doesn’t know how to use Invisible reCaptcha because it showed a new error “#0 Empty solution not allowed”. Umph!

#0 Empty solution not allowed

#0 invalid-keys

OK, then I tried some other combinations, e.g. enabling both “Captcha – ReCaptcha” and “Invisible reCaptcha” with a small hope that VirtueMart will use “Captcha – ReCaptcha” and that the Joomla contact form will use “Invisible reCaptcha” (as it was selected as default in the Global configuration). Needless to say that it didn’t work. This time it showed “#0 invalid-keys” error:

#0 invalid-keys

OK, after wasting 2.5 hours on that, it was time to stop experimenting and stick to the only solution that worked, i.e. enabling only “Captcha – ReCaptcha” and poor users will always need to confirm that they are not robots. I guess we all feel like robots sometimes when working on super-boring tasks, so at least this thing will remind us to stop being robots anymore 🙂

You may wonder why this 3rd captcha plugin “The new Recaptcha” in my configuration that caused me all this trouble. Well, this was downloaded from the web because of one experiment, but this plugin is not really needed because Joomla’s built in plugins seem to work just fine.

Customizing Joomla Contact Form

Suppose we want to customize Joomla contact form. We want to do two modifications:

  1. Set some default text into text fields, e.g. to E-mail subject text box
  2. Set content of these fields via the URL argument (querry string), e.g. www.yoursite.com/book-excursion?subject=Book%20excursion

The purpose of this for me is to be able to display a customized contact form, which is displayed upon click on a button. The form can be shown through different buttons, e.g. “Book Makarska Excursion”, “Book Biokovo Excursion”. The form sends e-mail to web site owner, so, to be able to tell from which button is e-mail sent (i.e. what is being booked), we show different versions of the contact form depending on which button is clicked.

To do this in Joomla 3.4 we need to modify the file JOOMLA_ROOT\components\com_contact\views\contact\tmpl\default_form.php. But of course, to preserve our changes when Joomla is updated, we need to copy this file into our Joomla template. So even if we update Joomla later, the modified version stays untouched. After some research, I found that the correct location where to put the file is:

JOOMLA_ROOT\templates\YOUR_TEMPLATE\html\com_contact\contact\default_form.php

To meet requirement 2., we need to get url arguments in PHP. E.g. if we want to get value of the argument “subject”, we do that like this: $_GET[“subject”].

And to meet requirement 1. we need to pass this value to the form field. The e-mail subject text box in Joomla is created like this:

$this->form->getInput(‘contact_subject’);

In Joomla documentation (https://api.joomla.org/cms-3/classes/JForm.html), we can see that default value can be set via the 3rd argument to getInput(), so finally we do like this:

$this->form->getInput(‘contact_subject’, null, $_GET[“subject”]);

We can now access the form with predefined Subject field via the link. E.g. if the contact form is normally accessed via www.yoursite.com/book-excursion, to set Subject field to “Book excursion”, call it via the following link:

www.yoursite.com/book-excursion?subject=Book%20excursion

Now you might ask yourself how to access the contact form via such an URL. The answer is simple, just create an invisible menu, add a new item to it that opens this contact form, and set menu alias to book-excursion. Although the menu is not visible (as it is not assigned to a module), menu item will be accessible via the alias. To get rid of “index.php” in the URL you also need to enable Apache mod_rewrite module, but that’s another story.

We want to do a few additional customizations. We just want to show the contact form, without contact details. Here is a solution for that: http://www.joomla-css.nl/en/styling-joomla-3-content-components/contact-and-contactform. Citing this website: “If you only want to show a contact form, you hide all options of the Contact Options, except set the “Display Format” on Plain. Then you only see a contact form on the page” . “The headings “Contact” and “Contact Form” are unnecessary on the page. To hide these headings we add the following CSS to the template.css:”

div.contact h3 {
display: none;
}

That’s all!

CustomizedJoomlaContactForm

Just imagine other beautiful stuff that can be done in similar way! 🙂 E.g. you can add one more URL argument “form_type” which will affect form shape, e.g. you can add some additional form fields like “Number of persons”.

The described method worked on Joomla 3.4, but should be identical (or very similar) for other Joomla versions. It should even work in Joomla 2.5 – I checked it and it has default_form.php file on the same location.