/** * Add element to form. * * @param CRM_Core_Form $form */ public static function add(&$form) { $error = NULL; $config = CRM_Core_Config::singleton(); $useSSL = FALSE; if (!function_exists('recaptcha_get_html')) { require_once 'packages/recaptcha/recaptchalib.php'; } // See if we are using SSL if (CRM_Utils_System::isSSL()) { $useSSL = TRUE; } $html = recaptcha_get_html($config->recaptchaPublicKey, $error, $useSSL); $form->assign('recaptchaHTML', $html); $form->assign('recaptchaOptions', $config->recaptchaOptions); $form->add('text', 'g-recaptcha-response', 'reCaptcha', NULL, TRUE); $form->registerRule('recaptcha', 'callback', 'validate', 'CRM_Utils_ReCAPTCHA'); if ($form->isSubmitted() && empty($form->_submitValues['g-recaptcha-response'])) { $form->setElementError('g-recaptcha-response', ts('Input text must match the phrase in the image. Please review the image and re-enter matching text.')); } }
/** * Implements hook_civicrm_validateForm(). * * @param string $formName * @param array $fields * @param array $files * @param CRM_Core_Form $form * @param array $errors */ function pledgeonlypage_civicrm_validateForm($formName, &$fields, &$files, &$form, &$errors) { $form->setElementError('pledge_installments', NULL); }