dqsong2010 2018-07-16 19:23
浏览 40
已采纳

PHP中每个按钮标签上的PHP增量,但不是发布的URL

I'm creating a web page that reads and displays files from a directory within the website, I'm using a for-each loop to iterate through the files and give the specific names based off the increment. When the user clicks the specific button I wan't my form to pass the specific increment so I know which file to use when it goes to the next page. The buttons display the increment as expected but the url always passes "1" as the value and I really dont know why, I attached a picture to show the buttons workingButtons Showing but the link always becomes 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>";
  • 写回答

1条回答 默认 最新

  • douzuqin3467 2018-07-16 19:36
    关注

    ID's of elements have to be unique. Currently you give your 'modal div' the same ID for every iteration in

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

    So what you should do are a few things: make sure the IDs are all unique (use your $zedvariable) and then have your data-target correspond to that unique ID (again with your $zed variable).

    EDIT: here's an example of how this would work:

    <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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改