mardi 18 septembre 2018

Echo text if no checkbox has been checked

I have the following checkbox form:

<p>
<label class="mtt" for="serie_mark"><h1><?php _e( 'Options', 'randomtheme' ); ?></h1></label>
<input type="radio" name="code_name" id="supi1" value="supi1" <?php echo ( series_get_meta( 'code_name' ) === 'supi1' ) ? 'checked' : ''; ?>>
<label for="supi1"><?php _e( 'Option 1', 'randomtheme' ); ?></label><br>
<input type="radio" name="code_name" id="pishti6" value="pishti6" <?php echo ( series_get_meta( 'code_name' ) === 'pishti6' ) ? 'checked' : ''; ?>>
<label for="pishti6"><?php _e( 'Option 2', 'randomtheme' ); ?></label><br>
<input type="radio" name="code_name" id="recky2" value="recky2" <?php echo ( series_get_meta( 'code_name' ) === 'recky2' ) ? 'checked' : ''; ?>>
<label for="recky2"><?php _e( 'Option 3', 'randomtheme' ); ?></label><br>
</p>

if ( isset( $_POST['code_name'] ) )
update_post_meta( $post_id, 'code_name', esc_attr( $_POST['code_name'] ) );

And I have the following script to display a message if a certain checkbox has been check:

<?php if($testing = series_get_meta('code_name')) { 
if ($testing == 'supi1') {
echo 'My text';
} elseif ($testing == 'pishti6') {
echo 'Another text';
} elseif ($testing == 'recky2') {
echo 'Some other text';
} else {
echo 'This is the default text for nothing selected';
} } ?>

Everything works great, it does register and display the message except one thing... it doesn't show a default message if a checkbox has not been selected. Any idea how to do this? Thanks.




Aucun commentaire:

Enregistrer un commentaire