Add reCAPTCHA into a custom mail form - Joomla! Forum - community, help and support


hi,
i trying add captcha mail form created intended sharing content,
but reason captcha not being validated when hit "submit", meaning if enter wrong text in captcha, form still send email.
i using joomla 2.5.8, apache2, recaptcha plugin enabled (although don't think being intialized since added recaptchalib.php myself , including ref publickey , privatekey inside mail form code).

any appreciated!
thank you!!
here code:

code: select all

<?php require_once('recaptchalib.php'); ?>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript">

              function validateemail($email)
   {
        var emailreg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
        if( !emailreg.test( $email ) )
        {
           return false;
        }
        else
      {
           return true;
        }
   }

   function validateform()
   {
      var form = document.mailform;
      if (form.recipient.value == "" || validateemail(form.recipient.value)==false)
      {
         alert("bad email");
         return false;
      }
      if (form.subject.value == "")
      {
         alert("please enter subject");
         return false;
      }
      if (form.content.value == "")
      {
         alert("please enter massage");
         return false;
      }
      <?php
      $privatekey = "privatekey"; 
      $resp = recaptcha_check_answer($privatekey,$_server["remote_addr"],$_post["recaptcha_challenge_field"],$_post["recaptcha_response_field"]);   ?>                
      if (!$resp->is_valid)
      {   
      alert("try again");
         return false;
       }
      return true;
   }      
</script>
<?php
   if($this->success=='1')
   {   
      echo jtext::_('mail_send_successfully');
   }   
   elseif($this->success=='0')
   {
      echo jtext::_('mail_send_failed');
   }   
?>
<div id="sendmail">
   <h2>send mail</h2>   
   <form action="index.php" name="mailform" method="post" onsubmit="return validateform()">

   <table>
      <tr>
         <td><label><?php echo jtext::_('mail_send_to'); ?>:</label></td>
         <td><input type="text" name="recipient" size="25" value=""/></td>
      </tr>
      <tr>
         <td><label><?php echo jtext::_('mail_subject'); ?>:</label></td>
         <td><input type="text" name="subject" size="25" value=""/></td>
      </tr>
      <tr>
         <td><label><?php echo jtext::_('mail_message'); ?>:</label></td>
         <td>
            <textarea name="content" rows="10" cols="40"></textarea>
            <br/><?php echo jtext::_('mail_desc'); ?>
         </td>
            <tr>
            <td><?php $publickey = "public key"; ?></td>
            <td><?php echo recaptcha_get_html($publickey);?></td>
            </tr>
   </table>      
   <p>
      <input type="hidden" name="controller" value="mail" />
      <input type="hidden" name="task" value="sendmail" />   
      <div class="button-mail">
         <input style="width: 50px;height: 25px;" type="submit" name="submit" value="<?php echo jtext::_('send'); ?>"/>
         <a href="javascript: void window.close()" title="close window"><span style="color: #444;
   border: #d5d5d5 1px solid; padding: 4px; width: 50px;height: 25px;"><?php echo jtext::_('close'); ?></span></a>
      </div>
   </p>
   </form>
</div>

can't instantiate/load recaptcha plugin manually using jpluginhelper???

you don't have much, load in thinking.





Comments

Popular posts from this blog

How to change text Component easybook reloaded *newbee* - Joomla! Forum - community, help and support

After Effect warning: A problem occurred when processing OpenGL commands

Preconditions Failed. - Joomla! Forum - community, help and support