pr-
pr-

Reputation: 402

PHP not receiving values for radio buttons

I'm using a PHP webpage to give me a list of all files with a .264 extension in a specific folder. The file is then selected and sent to a command to playback the video on a display attached to the computer.

I'm having difficulties trying to get the radio buttons to maintain their values, so that when they are selected and the form button is pressed, they do not know their values and are therefore not able to execute the script.

I know the script works, because I tested it with just a fill-in-the-blank type form and had no problems.

Now I'm listing the files with a radio button to select the file and submit it to the form to play, but it isn't working as I had hoped.

I've looked around and tried to figure it out. I'm not sure if I need to use a linked list or something instead of an array. This is my first time doing php coding, so I'm not sure where I should start to try to resolve this.

<?php
$FileCount = 0;
$currentdir = '/data/'; //Location of Hard Drive
$dir = opendir($currentdir);
$array = array();
echo '<ul>';
while ($File = readdir($dir)){


//if (is_file($file))

$ext = pathinfo($File, PATHINFO_EXTENSION);
if ($ext == '264'){


$array[] = "$File";

echo "<INPUT class='radio' type='radio' name='FileName' value='$File' /> <span>$File</span><p>";    

$FileCount++;   
}

}


echo '<form action="test.php" method = "post">';

echo "<INPUT TYPE = 'Submit' name = 'FormSubmit' value = 'Submit'>";

echo '</form>';


if ($_POST['FormSubmit'] == "Submit")
{
echo $_POST["FileName"];

 }

Nothing returns with this code. Any help would be great. Thanks.

Upvotes: 4

Views: 288

Answers (2)

voodoo417
voodoo417

Reputation: 12111

echo '<form action="test.php" method = "post">';

add this code below

while ($File = readdir($dir)){

Upvotes: 2

Jeff Lambert
Jeff Lambert

Reputation: 24671

If you want the values of the radio button controls to be sent along with the form post, then the controls themselves must be children of the form element.

<form method = "post" action = "">
<?php while ($File = readdir($dir)) { 
        if(pathinfo($File, PATHINFO_EXTENSION) == '264')) { ?>

        <input type = "radio" ... >
<?php 
        }
    } 
?>

    <input type = "submit" value = "Submit" name = "FormSubmit">
</form>

As you have it now, the radio buttons exist outside of the form, so they are not part of the form.

Upvotes: 4

Related Questions