I have a HTML form in a wordpress site that sends data to a database. One of the fields asks if a person is male or female using a radio button. How ever even if the persons presses the "Female" radio button they get set to male (Status M)
I've attached my code, the <?php if( get_theme_mod( 'petition_zip' ) === true ) : ?>
is only a check in my wordpress theme to see if the field should be there. I first tried using only HTML but added some PHP later to try and remidy the problem, it did not so as far as I can tell the PHP attached is close to useless
<?php
$male_status = 'unchecked';
$female_status = 'unchecked';
if (isset($_POST['submit'])) {
$selected_radio = $_POST['zip'];
if ($selected_radio == 'M') {
$male_status = 'checked';
}
else if ($selected_radio == 'F') {
$female_status = 'checked';
}
}
?>
<?php if( get_theme_mod( 'petition_zip' ) === true ) : ?>
<div class="form-group">
<input type="radio" id="zip" name="zip" value="M" <?PHP print $male_status; ?>>
<label for="M">Male</label>
<input type="radio" id="zip" name="zip" value="F" <?PHP print $female_status; ?>>
<label for="F">Female</label>
</div>
<?php endif; ?>
I'm running queries on the database to confirm the status, everyone that signs up is put to status "M" (Male)