PHP形成动态输入

时间:2014-05-11 10:39:04

标签: javascript php html forms

非常新的PHP ...忍受我!

我正在创建一个摄影网站,我被困在一个特定的页面上。最终,我需要页面成为具有动态输入数量的表单。它将是我的Web主机服务器上文件夹(或“图库”)的动态可视化表示。每个div块将包含文件夹中的第一个图像以及文件夹的名称 - 标题文本和图像都应该是可点击的,并作为提交按钮继续到album.php页面,通过文件夹的名称传递一个GET方法。

我遇到的第一个问题是尝试从表单中删除提交按钮,并在<a>标记中替换我的相册缩略图和专辑标题。显然是通过javascript,我设法让这个工作 - 有点。我已经将页面置于一个状态,其中有一个表单,有多个输入,但现在每个文件夹名称都在URL中传递(例如mywebsite.com/album.php?name=album1&name=album2&name = album3)我绝对卡住了!

代码包含在内,所以如果有人可以查看并提供一些指导或指出我正确的方向(并提供任何其他新手提示!),我们将不胜感激。

干杯 利

<form id="album" method="get" action="album.php">

<?php
    $basepath = 'images/portfolios/public/';
    $results = scandir($basepath);

    foreach ($results as $result) {
            if ($result === '.' or $result === '..') continue;

            if (is_dir($basepath . '/' . $result)) {
                //create new gallery for each folder
              ?>

                 <div class="gallery">

                    <?php

                       //get count of images in folder
                   $i = 0; 
                   $path = 'images/portfolios/public/' . $result;

                   if ($handle = opendir($path)) {
                      while (($file = readdir($handle)) !== false){
                          if (!in_array($file, array('.', '..')) && !is_dir($path.$file)) 
                          $i++;
                      }
                       }

               //create array, and choose first file for thumbnail
                   $files = array();   
               $dir = opendir($path);   
               while(($file = readdir($dir)) !== false)   
               {   
                  if($file !== '.' && $file !== '..' && !is_dir($file))   
                  {$files[] = $file;} 
               }   
               closedir($dir);   
               sort($files);   

               //form input - album name for next page
               echo '<input type="hidden" name="name" id="name" value="'.$result.'" />';

               //the headline and image link for gallery
                   echo '<a href="javascript: submitform()">' . $result . ' - ('.$i.' images)<br>
                   <img src="'.$path.'/'.$files[0].'" />
                   </a>';

                ?>

             </div> <!-- end gallery -->


                 <?php }
          }
        ?>

</form>
<script type="text/javascript">
function submitform(){document.forms["album"].submit();}
</script>

1 个答案:

答案 0 :(得分:0)

更改您的代码:

echo '<a href="javascript: submitform()">' . $result . ' - ('.$i.' images)<br>
          <img src="'.$path.'/'.$files[0].'" />
      </a>';

到此代码:

echo '<a href="admin.php?name='.$result.'">' . $result . ' - ('.$i.' images)<br>
          <img src="'.$path.'/'.$files[0].'" />
      </a>';
相关问题