dqsong2010
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
    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>
    
    点赞 评论

相关推荐