babyewok Posted December 20, 2013 Share Posted December 20, 2013 I want to add a new honeypot field to the contact form. This form will be hidden by css and should be submitted empty. However if it is completed by a bot, then the form will not be sent, so I need to show an error message if the field contains any content. There is no need for this to the added to the database as the form will never be sent if it contains content. I have added this to contact-form.tpl: <p class="sticky"> <label for="sticky">{l s='Sticky'}</label> <input type="text" id="sticky" name="sticky" value="{if isset($smarty.post.sticky)}{$smarty.post.sticky}{/if}" /> </p> Now I am trying to override ContactController.php in order to show an error message when the field is NOT empty. However, I just can't seem to get it working. How can I test to see if this field is empty and, if not, show an error message? I am using PS 1.4.11 Link to comment Share on other sites More sharing options...
babyewok Posted December 20, 2013 Author Share Posted December 20, 2013 (edited) Well I seem to be almost there. I added this to my ContactController.php: if (($sticky = trim(Tools::getValue('sticky'))) OR (($sticky = nl2br2($sticky)))) $this->errors[] = Tools::displayError('Sorry, this form will not be sent'); Which seems to work: if I enter content in the sticky field then the error shows correctly. HOWEVER, for some obscure reason, if I do not enter any content, then any other errors (i.e. no message or subject line) are repeated twice. What is causing this to happen, I haven't edited those errors at all. EDIT: Actually, the 'sticky' error message only shows if the message OR subject line are empty. If the subject line and message are completed then the sticky error just doesn't work! Why is it linked in with the other errors like this? Edited December 20, 2013 by babyewok (see edit history) 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