PHP does not get values ​​for switches

I am using a PHP webpage to give me a list of all files with a .264 extension in a specific folder. Then the file is selected and sent to the team to play the video on the screen attached to the computer.

I'm having difficulty trying to get the switches to maintain their values, so when they are selected and the form button is pressed, they don’t know their values ​​and therefore can’t execute the script.

I know the script works because I tested it only with the fill form in the empty form and had no problems.

Now I am listing the files using the switch to select the file and submit it to the form for playback, but it does not work as I hoped.

I 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 I'm doing php coding, so I'm not sure where I should 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.

+4
source share
2 answers
 echo '<form action="test.php" method = "post">'; 

add this code below

 while ($File = readdir($dir)){ 
+2
source

If you want the values ​​of the switch controls to be sent along with the form message, the controls themselves must be child elements 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 can see now, radio buttons exist outside the form, so they are not part of the form.

+4
source

All Articles