0

Hi i'm trying to fill a variable (location) with a selected image, the images are coming from a folder on the server and I want the user to be able to pick an image, fill in the rest of the textboxes and when submit is pressed send these variables to another form.

The other forms work fine, I just don't know how to get the value of the radio button to the text variable location. I previously had the user fill a textbox with the whole path

Thanks in advance and Happy Holidays

<form action="appendlist.php" method="post">
          <input name="title" type="textbox" placeholder="Title" class="form-control" ><br><br>
          <input name="alt" type="textbox" placeholder="Alt text" class="form-control" ><br><br>
          <input name="caption" type="textbox" placeholder="Image caption" class="form-control" ><br><br>


    <?php
    $dir = 'images/comics/'; 
    if (!isset($_POST['submit'])) 
    { 
        if ($dp = opendir($dir)) 
        { 
            $files = array(); 
            while (($file = readdir($dp)) !== false) 
            {
                if (!is_dir($dir . $file)) 
                { 
                    $files[] = $file; 
                } 
            }
                closedir($dp); 
        } 
        else 
        { 
            exit('Directory not opened.'); 
        } 


        if ($files) 
        { 
            echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">'; 
            foreach ($files as $file)
            { 
                echo '<input type="radio" name="files[]" value="' . $file . '" /> ' . 
                $file . '<br />'; 
            } 
            echo '</form>'; 
        }

        else 
        { 
            exit('No files found.'); 
        } 

    }

    else 
    { 
        if (isset($_POST['files'])) 
        { 
            foreach ($_POST['files'] as $value) 
                { 
                echo $dir . $value . '<br />';
                } 

        }

        else
        { 
            exit('No files selected'); 
        } 
    }
    ?>
        <br>
        <input name="password" type="textbox" placeholder="Enter password" class="form-control" >
        <br>

        <!--<input name="location" type="textbox" placeholder="File location" class="form-control`"-->

        <input type="submit" value="Add to reel" name="submitappend">
        </form>
Craig Harley
  • 304
  • 5
  • 18
  • You have two times a form element. And if the form action is pointing to the same URI you can just leave it out. And never use `$_SERVER['PHP_SELF']` because it is insecure, please see [PHP_SELF and XSS](http://stackoverflow.com/q/6080022/367456) - And what is your concrete question. So far I have understood something does not work for you, but what is your programming question here? http://stackoverflow.com/help/on-topic – hakre Dec 26 '14 at 16:16

1 Answers1

0

You can not have nested form like form inside another form, in your case you are creating nested form..Please close the from previously opened before loop....

Vijay Sankhat
  • 341
  • 3
  • 17