lundi 11 décembre 2017

PHP checkboxes posting even when not checked

Am working in PHP. Everything (except for the checkboxes) works in the form, including the error correction, the text file it writes to and the notification email.

For the sake of brevity I've included only the relavent code.

Objectives for textboxes: 1. If selected they should remain checked during error correction. 2. If selected, the $Newvar_ should post an "X" in the email and text file.

Currently they always post an "X" regardless if they are checked, or not.

Thanks in advance for any suggestions.

<?php

/// php error checking of required submitter ID fields here ///

{

// Change the checkbox 'on' to an "X"
// These fields and not required or error checked
if($Form_F_029 == 'on') $Newvar_029 = &$Form_F_029; $Newvar_029 = "X";
if($Form_F_032 == 'on') $Newvar_032 = &$Form_F_032; $Newvar_032 = "X";
if($Form_F_033 == 'on') $Newvar_033 = &$Form_F_033; $Newvar_033 = "X";


// Format the fields for the email notification
fwrite($file,

/// Formatted submitter ID fields here ///

Form F-029:\t $Newvar_029
Form F-032:\t $Newvar_032
Form F-033:\t $Newvar_033

fclose($file);
}

// Format and send email notice of successful submittal
if ($_POST['submit']) {

/// email dialogue here ///

}
?>

<!DOCTYPE HTML>
<html>
<title>Page Title</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" media="screen" />
</head>
<body>

<form action="<?=$_SERVER['PHP_SELF']?>" name="inquiry" method="post">

/// required submitter ID Fields here ///

<div class="field third first">
   <input type="checkbox" id="Form_F_029" name="Form_F_029" <?php if($Form_F_029 == "on"){echo "CHECKED";}?> />
   <label for="F_029"><a href="../../../forms_resources/order-forms/pdf/Form_F_029.pdf">Form F 029</a>
   </label>
</div>
<div class="field third">
   <input type="checkbox" id="Form_F_032" name="Form_F_032" <?php if($Form_F_032 == "on"){echo "CHECKED";}?> />
   <label for="Form_F_032"><a href="../../../forms_resources/order-forms/pdf/Form_F_032.pdf">Form F 032</a>
   </label>
</div>
<div class="field third">
   <input type="checkbox" id="Form_F_033" name="Form_F_033" <?php if($Form_F_033 == "on"){echo "CHECKED";}?> />
   <label for="Form_F_033"><a href="../../../forms_resources/order-forms/pdf/Form_F_033.pdf">Form F 033</a>
   </label>
</div>

<ul class="actions">
<li><input type="submit" class="button small" name="submit" id="submit" value="Send Inquiry" /></li>
</ul>

</form>

<div id="error" title="Form Errors:">
<?php
if (!empty($errors))
{
echo "<div style=\"padding:15px 15px 0 15px\">";
echo "<ul style=\"margin-bottom:20px\">";
foreach ($errors as $error)
echo "<li style=\"font-size:15px; padding:5px\">$error</li>";
echo "</ul></div>";
}
?>
</div>

<!-- JS at the end -->

<script src="/assets/js/jquery.min.js"></script><!-- ver: 1.11.3 -->

<script src="http://ift.tt/2dsPzTA"></script>  

<script>
$('#error').dialog({
height: 380,
width: 260,
modal: true,
resizable: false,
dialogClass: 'no-close error-dialog'
});
</script>

</body>
</html>




Aucun commentaire:

Enregistrer un commentaire