PHP + jQuery .validate issue
Ill try and make this as clear as possible. I have a contact form on a page and a remote PHP file "random.php" that generates 2 random numbers:
<?php
$randomNum = rand(0,9);
$randomNum2 = rand(0,9);
echo $randomNum . ' + ' . $randomNum2;
$randomNumTotal = $randomNum + $randomNum2;
?>
the parent page calls it as such:
$(function() {
$.get( 'PHP/random.php', function ( data ) {
$('#ResetNumbers").val(data);
});
and has an input:
<input type="text" class="numbers" name="ResetNumbers" id="ResetNumbers" value="" size="6" readonly>
No problems to this point, the php file output's the two random numbers and they are displayed on the page. Here's the problem: I have a second text box where you have to add the two numbers to make it va开发者_StackOverflow社区lidate.
<input type="text" class="numbers" name="ResetMath" id="ResetMath" size="6" maxlength="6" tabindex="27">
It never works. It always says its not added correctly. here is the relevant part of my validation rule which is in another remote file:
ResetMath: {
required: true,
equal: <?php echo $randomNumTotal; ?>
}
Since this is in a remote file (don't want validation rules on the parent page) it doesn't seem to be getting the same numbers. How do I unscrew this mess?
ResetMath: {
required: true,
equal: <?php echo $randomNumTotal; ?>
}
doesn't seem right. It should be:
ResetMath: {
required: true,
equalTo: $('#ResetNumbers')
}
The API is here.
How does your validation rule get its value for $randomNumTotal? is this in the same request as the one which returns the values for $randomNum and $randomNum2? If not, you have a problem - (different random numbers for each).
精彩评论