首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >For-each中的PHP Increment适用于按钮标签,但不适用于发布的URL

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

Stack Overflow用户
提问于 2018-07-17 03:23:24
回答 1查看 80关注 0票数 0

我正在创建一个web页面,用于读取和显示网站内某个目录中的文件,我使用for-each循环遍历这些文件,并根据增量给出具体的名称。当用户单击特定的按钮时,我不希望我的表单传递特定的增量,这样我就知道当它转到下一个页面时使用哪个文件。按钮按预期显示增量,但是url总是传递"1“作为值,我真的不知道为什么,我附上了一张显示按钮工作的图片。

但是链接总是变成http://Mywebsite.com/AuthorizeCapabilityRequest.php?1

代码语言:javascript
复制
<?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>";
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-17 03:36:54

元素的ID必须是唯一的。中的每次迭代都给'modal div‘相同的ID。

代码语言:javascript
复制
<div class='modal fade' id='exampleModalCenter' tabindex='-1' 
role='dialog' aria-labelledby='exampleModalCenterTitle' aria-hidden='true'>

因此,您应该做几件事:确保ID都是惟一的(使用$zed变量),然后让data-target对应于这个惟一的ID(同样使用$zed变量)。

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

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51368816

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档