繁体   English   中英

For-each中的PHP增量适用于按钮标签,但不适用于发布的URL

[英]PHP Increment in For-each Works on Buttons Labels but not on Posted URL

我正在创建一个从网站目录中读取和显示文件的网页,我使用了for-each循环来遍历文件并根据增量指定具体名称。 当用户单击特定按钮时,我将不希望表单传递特定增量,因此我知道在转到下一页时要使用哪个文件。 按钮显示了预期的增量,但是url始终将值传递为“ 1”,我真的不知道为什么,我附上了一张图片以显示按钮的作用 按钮显示 但是链接始终变为http://Mywebsite.com/AuthorizeCapabilityRequest.php?1

<?php

$images = glob($directory . "*.*");
 echo "<div class='col-md-12' align='center'><div class='col-md-10'>
       <table class='table table-bordered table-striped'>
      <tr>
        <th width='65%'>Filename</th>
        <th width='20%'>Edit</th>
        <th width='15%'>Refer</th>
      </tr>";
    $dir = "Capability_Request/*";
    $zed = 1;


    foreach(glob($dir) as $file)
    {

        $base = basename($file);

        echo "<tr><td>";
        if(!is_dir($file)) { echo basename($file);}
        echo "</td><td><button type='button' class='btn btn-primary btn- 
             small' data-toggle='modal' data-target='#exampleModal$zed'>
          $zed

        </button> </td><td>

        <!-- Button trigger modal -->
        <button type='button' class='btn btn-primary' data-toggle='modal' 
         data-target='#exampleModalCenter'>
          $zed
        </button>

        <!-- Modal -->
        <div class='modal fade' id='exampleModalCenter' tabindex='-1' 
           role='dialog' aria-labelledby='exampleModalCenterTitle' aria- 
          hidden='true'>
          <div class='modal-dialog modal-dialog-centered' role='document'>
            <div class='modal-content'>
              <div class='modal-header'>
                <h5 class='modal-title' id='exampleModalLongTitle'>Refer 
                  Capability to UNF</h5>
                <button type='button' class='close' data-dismiss='modal' 
                aria-label='Close'>
                  <span aria-hidden='true'>&times;</span>
                </button>
              </div>
              <div class='modal-body'>";



                $url = "AuthorizeCapabilityRequest.php?".$zed;
                echo "<form action='$url' method='post'>";                  

                echo "<h6>If you would like to refer the capability to the 
                     UNF, and accept the capability request, select this 
                     button:</h6>";

                echo "<input class='btn btn-success btn-block' type='submit' 
                    value='Submit'>";
                echo "<hr>";
                echo "<h6>If you would like to refer the capability to the 
                      UNF, but deny the capability request, select this 
                      button:</h6>";
                echo "<button type='button' class='btn btn-warning btn- 
                      block'>Refer</button>";
                echo "<hr>";
                echo "<h6>If you would like to deny the capability referral 
                     to the UNF, select this button:</h6>";
                echo "<button type='button' class='btn btn-danger btn- 
                    block'>Deny</button>";
                echo "<div class='modal-footer'>";

                echo "<button type='button' class='btn btn-secondary' data- 
                    dismiss='modal'>Cancel</button>";

              echo "</form>";
              echo "</div>";                  
            echo "</div>";
          echo "</div>";
        echo "</div>";
    echo "</td></tr>";

    $zed++;             
    }       
echo "</table></div></div>";

元素的ID必须是唯一的。 目前,您为“模态div”的每次迭代赋予相同的ID

<div class='modal fade' id='exampleModalCenter' tabindex='-1' 
role='dialog' aria-labelledby='exampleModalCenterTitle' aria-hidden='true'>

因此,您应该做的是几件事:确保ID都是唯一的(使用$zed变量),然后使data-target与该唯一的ID对应(再次使用$zed变量)。

编辑:这是一个如何工作的示例:

<button type="button" data-toggle="modal" data-target="#exampleModal<?php echo $zed; ?>">
your button
</button>

<div class="modal" id="exampleModal<?php echo $zed; ?>">
your modal
</div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM