bondimedical Posted October 11, 2015 Share Posted October 11, 2015 I would like to install a simple recaptcha on my Contact Us page and am using the tutorial here - http://myphpform.com/form-spam.php - The HTML is not a problem but the PHPif (strtolower($_POST['code']) != 'mycode') {die('Wrong access code');}is the issue. How do I change this so it displays the error message for Cubecart? Quote Link to comment Share on other sites More sharing options...
bsmither Posted October 11, 2015 Share Posted October 11, 2015 One idea would be to use the $GLOBALS['gui']->setError('Wrong access code.'); function. Followed by httpredir();. Quote Link to comment Share on other sites More sharing options...
bondimedical Posted October 13, 2015 Author Share Posted October 13, 2015 I have managed to get it to work with the following code:if (strtolower($_POST['captcha']) != 'mycode') {$GLOBALS['gui']->setError('The code entered was incorrect. Please try again.'); httpredir('index.php?_a=contact'); }But what it does is clear the form of all the details which the customer entered, name, email etc. How can I prevent this from happening? Quote Link to comment Share on other sites More sharing options...
bsmither Posted October 13, 2015 Share Posted October 13, 2015 The function CubeCart->_contact() is already coded to handle sending the visitor back to a fully-populated Contact Us page if any of several tests fail.Basically, it assigns the $_POST['contact'] form elements back to a template variable, even if that variable won't be used if successful. But if an error is detected, the code falls through to displaying the form, but this time the form's elements are populated.Are you constructing a separate Contact Us page?Do you have CubeCart's reCaptcha enabled? Quote Link to comment Share on other sites More sharing options...
bondimedical Posted October 13, 2015 Author Share Posted October 13, 2015 No I am not making a separate Contact Us page. It's just the normal CubeCart one.CubeCart's reCaptcha is disabled. Quote Link to comment Share on other sites More sharing options...
bsmither Posted October 13, 2015 Share Posted October 13, 2015 Ok, then try this. In /classes/cubecart.class.php:Find near line 1336: private function _contact() { dbgClue(__METHOD__); // Contact Form $contact = $GLOBALS['config']->get('Contact_Form'); if ($contact && $contact['status']) { $GLOBALS['gui']->addBreadcrumb($GLOBALS['language']->documents['document_contact'], currentPage()); if (isset($_POST['contact'])) { foreach ($GLOBALS['hooks']->load('class.cubecart.contact') as $hook) include $hook; $GLOBALS['smarty']->assign('MESSAGE', $_POST['contact']); // Validation $error = false; We need to move the default setting of the $error variable above the hook. Change to: private function _contact() { dbgClue(__METHOD__); // Contact Form $contact = $GLOBALS['config']->get('Contact_Form'); if ($contact && $contact['status']) { $GLOBALS['gui']->addBreadcrumb($GLOBALS['language']->documents['document_contact'], currentPage()); if (isset($_POST['contact'])) { $error = false; foreach ($GLOBALS['hooks']->load('class.cubecart.contact') as $hook) include $hook; $GLOBALS['smarty']->assign('MESSAGE', $_POST['contact']); // Validation We can now use the hook, or simply add the new statement just after the hook.if (strtolower($_POST['captcha']) != 'mycode') { $GLOBALS['gui']->setError('The code entered was incorrect. Please try again.'); $error['captcha'] = true; }Now that $error is no longer false, the Contact Us form will be re-displayed. Quote Link to comment Share on other sites More sharing options...
bondimedical Posted October 13, 2015 Author Share Posted October 13, 2015 Works perfectly. Thank you very much for your help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.