Biscuit128
Biscuit128

Reputation: 5398

Printing radio button value in php

I am trying to print the selected radio button value on a new page - my code looks as follows

function printUserApplicationSelectionForm($applicationsForUser){

    ?>
    <form action="test.php" method="post">
    <?php   
    foreach ($applicationsForUser as $app) {    
        $name = $app->getName();
        $appId = $app->getApplicationId();
    ?>
        <input type="radio" name="appNames" value="<?php $appId ?>"> <?php echo $name ?> <br>

    <?php
    }
    ?>
    <input type="submit" name="submitRadio" value="Submit"><br>
    </form>
    <?php
}



<?php
if(isset($_POST['submitRadio'])){
    $selected_radio = $_POST['appNames'];
    echo "1234";
}else{
    echo "is not";
}

?>

If i print explicit values like 1234 it prints without an issue- however printing $selected_radio does not - why would this variable be empty?

Thanks

Upvotes: 1

Views: 656

Answers (1)

Pramod
Pramod

Reputation: 2896

You are missing to echo the value in the radio button tag

This should be

<input type="radio" name="appNames" value="<?php echo $appId ?>"> <?php echo $name ?>

Upvotes: 2

Related Questions