samedi 2 juillet 2016

PHP use session for radio button or set default

On my upload form for an image gallery I have two radios - one for "fullsize" and one for "thumbnails". I managed (thx to stackoverflow) to keep the last checked radio button checked, but I'd now also like to set the "full"-one as default, i.e. if there's nothing set (!isset), e.g. when first opening the form, it should be checked. below is how far I got, I really can't see what I'm missing, help please!

<?php
// the session:
session_start();
if(isset($_POST['kategorie'])){
$_SESSION['kategorie']=$_POST['kategorie'];}
if(isset($_POST['size'])){
$_SESSION['size']=$_POST['size'];}
?>

<?php
// and the radio buttons:
<input type="radio" name="size" value="full" id="regularRadio"
        <?php
                if (isset($_SESSION['size'])) {
                        if($_SESSION['size'] == "full") {
                                echo " checked='checked'";      
                        } elseif (!isset($_SESSION['size'])) {
                                echo " checked='checked'";
                        }
                }
                ?> >
        <label for="regularRadio">Full size</label>
        <br>              
        <input type="radio" name="size" value="thumb" id="thumbRadio"
        <?php
                if (isset($_SESSION['size'])) {
                        if($_SESSION['size'] == "thumb") {
                                echo "checked=' checked'";      
                        }
                }
                ?> >
        <label for="thumbRadio">Thumbnail</label>
?>

Aucun commentaire:

Enregistrer un commentaire