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

  • Home
  • SEARCH
  • 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 3991566
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:37:53+00:00 2026-05-20T06:37:53+00:00

Been struggling with this for a couple days now. Here’s the set up –

  • 0

Been struggling with this for a couple days now. Here’s the set up – I have a parent page “support.php” there are tabs, and when you click a tab it brings in the appropriate form via ajax.
(the relevant code for each section:)

form input’s on the AJAX page

<input type="text" class="numbers" name="captchaImage" id="SupportNumbers" size="6" value="" readonly>
<input type="text" class="numbers" name="SupportMath"  id="SupportMath" size="6" maxlength="6" tabindex="9">

The parent page – support.php calls for “validation.js” which is my jQuery.validate script.

...
SupportMath: {
    required: true,
    equal: "<?php echo $randomNumTotal; ?>" 
}

There is a .get command on the parent page for a file “random.php”

$.get('PHP/random.php', function (data){
    $("#SupportNumbers").val(data);
});

<?php
    $randomNum = rand(0,9);
    $randomNum2 = rand(0,9);
    echo $randomNum ."+". $randomNum2;
    $randomNumTotal = $randomNum + $randomNum2;
?>

which generates two random numbers so you can add them together. The validation checks to make sure
the two numbers that are generated are added correctly. I just can’t seem to get all these pieces to use the same numbers, i can get the text box “SupportNumbers” to populate with two random numbers say “2 + 5” but when I enter “7” into “#SupportMath” it displays the error msg. It should be $randomNumTotal but I can’t get that to the page, and have the validation script check against that.
HELP.

I realize this is clear as mud so ill try and explain more
I have 5 forms on my support page. To reduce the chaos, I have them in a vertical tab set. I don’t want my js validation script on the page and I don’t want all 5 forms hidden/displayed on the page due to some issues we’ve had with some bots. So my solution was to bring in the forms with AJAX (done) and just link to the validation script (done) all is good except for our “random math captcha” I can put it in a file and use the “.get” command to populate the box that holds the two random math questions, but can’t get the answer to validate. Hope this helps, code below.

  • 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-05-20T06:37:54+00:00Added an answer on May 20, 2026 at 6:37 am

    EXPLANATION: ( step by step )

    • we use your method to generate two random number from 1 to 9 at page load
    • we have added an extra input <input type="hidden" name="math" id="math"/> this field is needed since you are using a readonly field, now the readonly fields are not submitted…by forms, this way we have the one shown to user and another one hidden, this one will be submitted;
    • we get the #math value that is a string ex: 5+2 so we need to transform this into two int and sum it.
    • finally we make the check the SUM against the user input #SupportMath

    • DEMO: https://so.lucafilosofi.com/php-jquery-validation/

    PHP ( that check the match against… )

    if ( isset($_POST['post']) ) {  
      $math = explode('+',trim($_POST['math']));
      $sum = ( (int)$math[0] + (int)$math[1] );
      $message = 'error';
      if ( (int)$sum === (int)$_POST['SupportMath'] ) {
      $message = 'success';
      }
      echo $message;
    }
    

    jQuery ( pseudo code…)

    $(function() {
        $.get('random.php',function(data) {
            $("#SupportNumbers,#math").val(data);
        });
        $('#form').submit(function(e) {
            e.preventDefault();
            var query = $(this).serialize();
            $.ajax({
                type: "POST",
                url: "post.php",
                data: "post=post&" + query,
                success: function(msg) {
                    if (msg.indexOf('success') == -1) {
                        alert('error');
                    } else {
                        alert('cURL');
                    }
                }
            });
        });
    });
    

    HTML

    <input type="text" class="numbers" name="captchaImage" id="SupportNumbers" size="6" readonly>
    <input type="hidden" name="math" id="math"/>
    <input type="text" class="numbers" name="SupportMath"  id="SupportMath" size="6" maxlength="6" tabindex="9">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been struggling with this one for a couple of days now. My current
I've been grappling with this one for a couple of days now, but I've
I've been struggling with a problem for the past couple days and haven't found
I've been struggling with some code for a paging for a couple of days
Has been struggling on this for a week I have two classes WiFiScanReceiver which
I've been struggling for a few days with this problem , learning a lot
A coworker has been struggling with this problem. The desired result is an installable
I've been struggling with this check constraint for a few hours and was hoping
I've been struggling with this one SQL query requirement today that I was wondering
This is a bit of a strange one, but I've been struggling for a

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.