Search code examples
phphtmlformsradio-buttonhttp-post

Why I do not get radio button value with php?


I´m passing a value of a radio button in a page with a form and I want to get the value of the selected option in another php file, but I can´t get that value.

First page:

<form class="itemSelection" action="../php/itemSelection1Save.php"><br><br>
    <h1>Recommended Item(s)</h1>
    <table class="itemTableRecom">
        <thead>
            <tr>
                <th>Selected Item Type</th>
                <th>Recommended Item Type</th>
            </tr>
        </thead>
        <tbody>
            <?php
            foreach ($_SESSION['itemsInfo'] as $row) {
                ?>
                <tr>
                    <td><input type="radio" name="selectedItem" id="selectedItem" required="" value="<?php echo $row[0] ?>"></td>
                    <td><?php
                        echo row[0]</td>
                </tr>
                <?php
            }
            ?>
        </tbody>
    </table><br>
    <input type="submit" value="Next"/>
</form>

Second file:

$_SESSION['selectedItem1'] = filter_input(INPUT_POST, 'selectedItem');

filter_input(INPUT_POST, 'selectedItem') 

returns nothing


Solution

  • You form is with method get (the default method if not specified):

    <form class="itemSelection" action="../php/itemSelection1Save.php">
    

    insert method='post':

    <form class="itemSelection" action="../php/itemSelection1Save.php" method='post'>