Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9244315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:59:49+00:00 2026-06-18T08:59:49+00:00

I am trying to add ReCaptcha into a mail form that I created which

  • 0

I am trying to add ReCaptcha into a mail form that I created which is intended for sharing content,
but for some reason the captcha is not being validated when I hit “submit”, meaning that even if you enter a wrong text in the captcha, the form will still send the email.
I am using joomla 2.5.8, the recaptcha plugin is enabled (although I don’t think it is being intialized since I added the recaptchalib.php myself and I am including the ref to the publickey and privatekey inside the mail form code).

Any help would be very much appreciated!
Thank you!!
here is the code:

<?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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:59:50+00:00Added an answer on June 18, 2026 at 8:59 am

    You have error in the code. Please look this lne

    if (!$resp->is_valid) 
    {    
        alert("try again");
        return false;
    }
    

    Where $resp->is_valid is the PHP but executed as JS.

    1. Correct code would be

      if (!<php (int)$resp->is_valid;?>) 
      {    
          alert("try again");
          return false;
      }
      

      But it will not work anyway because of 2.

    2. You cannot check recaptcha code in Javascript validation. It should be checked server side. Or if you want to check with javascript it should be checked with AJAX request to server. That is because you code

      <?php 
      $privatekey = "privatekey";  
      $resp = recaptcha_check_answer($privatekey,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"],$_POST["recaptcha_response_field"]);   ?>                 
      

      is executed on form load before even user eneter captcha.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm trying add malloc to a phonebook application that I created, but since
Trying to add a class object into a List using reflection, but when invoking
I'm trying add some implicit rules in CMake that will generate direct dependencies (like
I'm trying add vertical lines to my grid. I have found some examples but
Trying to add some html to a TextArea in Mobile Flex 4.5 but keep
Trying to add event handlers to radio buttons that are created on user input,
Trying to add content to my database using a form and JSON. My query
I am trying to add a reCAPTCHA to my PHP contact form with AJAX.
trying to add an ExpiresDefault ExpiresByType to content on my website so that way
Im new to asp.net mvc. I'm trying add new model class but it got

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.