簡體   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