Need help reading variable on POST

Need help reading variable on POST

Hello,

I have a PHP page that makes a checkbox appear after a certain textbox is exited. This part of the functionality is working - the user leaves the textbox, the AJAX call is made, and if certain criteria are met, the checkbox appears or it doesn't.

Here's where I need help. When the checkbox appears on the form and the form is submitted via POST, I can't get its value.


  1. <!DOCTYPE html> <html lang="en"> <head> <script type="text/javascript" src="jquery-1.4.4.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#num2').blur(function(){ $.post("biz/add_official.php", { num1: $('#num1').val(), num2: $('#num2').val() }, function(response){ $('#usernameResult').fadeOut(); setTimeout("finishAjax('usernameResult', '"+escape(response)+"')", 400); }); return false; }); }); function finishAjax(id, response) { $('#'+id).html(unescape(response)); $('#'+id).fadeIn(); } //finishAjax </script> </head> <body> <?php if(isset($_POST['submitCheck'])){ // the form has been submitted $checkOfficial = trim($_POST['checkOfficial']); echo "'" . $checkOfficial . "'"; exit; } ?> <form name="goAdd" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" onsubmit="return validateForm(this)"> <input type="text" name="num1" id="num1" size="3" maxlength="3" value="<?php echo htmlspecialchars(stripslashes($num1)) ?>"> <input type="text" name="num2" id="num2" size="3" maxlength="3" value="<?php echo htmlspecialchars(stripslashes($num2)) ?>"> <span id="usernameResult" style="color:green;"></span> <script> $('.container').find('.checkOfficial input[type="checkbox"]').val() </script> <input type="submit" value="Add Question" name="submitCheck"> </form> </body> </html>


When the form is submitted via POST, how do I see if checkbox was checked or unchecked?

  $_POST['checkOfficial']  appears empty when I submit the form.

Here's biz/add_official.php:

  1. <?php $num1 = $_POST['num1']; $num2 = $_POST['num2']; if((is_numeric($num1)) && (is_numeric($num2)){ print "<input type=\"checkbox\" name=\"checkOfficial\" id=\"checkOfficial\" checked> Submit this id number officially."; } ?>