2016-05-13 8 views
0

私はSESSIONにmysqlのデータを格納し、それを別のページに渡して、すべてのデータをzipにしてダウンロードします。これまでのところすべてが完璧に機能します。セッションのモーダル入力フィールドからテキストを保存します

ダウンロードボタンをクリックする前に、実際にダウンロードしてzipアーカイブの名前をモーダルウィンドウに入力してからアーカイブをダウンロードするようにしています。これまではモーダルを作成しましたが、入力フィールドのテキストをセッションに渡す方法はわかりません。他のすべてのデータは正しく渡されます。ここで、ソースは、これまでのところで、私は$_SESSION['itemid']からすべて取るcreate_zip.php

if(! isset($_POST['showcart'])) exit; 
echo '<a class="btn btn-danger btn-lg pull-right" style="margin: 10px;" data-toggle="modal" data-target="#myModalNorm">Download All Files</a> 
<table class="table table-striped table-bordered table-condensed responsive" id="sort"> 
        <thead> 
       <tr> 
        <th>ID</th> 
        <th>Title</th>     
        <th>Description</th>    
        <th>Action</th> 
       </tr> 
        </thead>'; 
foreach ($_SESSION['itemid'] as $i): 

    $sql = "SELECT * FROM uploads WHERE upload_id = :id"; 
    $result = $pdo->prepare($sql); 
    $result->bindParam(":id", $i); 
    $result->execute();     

    $resArray = $result->fetchAll(); 

    foreach ($resArray as $row):?> 

     <div class="row"> 
      <div class="box-content"> 
       <tbody> 
     <tr>  
      <td class="center"><?=$row["upload_id"]?></td> 
      <td class="center"><?=$row["upload_title"]?></td>      
      <td class="center"><?=$row["upload_description"]?></td> 
     </tr> 
       </tbody> 
      </div> 
     </div> 
     <!-- Modal --> 
     <div class="modal fade" id="myModalNorm" tabindex="-1" role="dialog" 
      aria-labelledby="myModalLabel" aria-hidden="true"> 
      <div class="modal-dialog"> 
       <div class="modal-content"> 
        <!-- Modal Header --> 
        <div class="modal-header"> 
         <button type="button" class="close" 
          data-dismiss="modal"> 
           <span aria-hidden="true">&times;</span> 
           <span class="sr-only">Close</span> 
         </button> 
         <h4 class="modal-title" id="myModalLabel"> 
          Please enter the name for the archive 
         </h4> 
        </div> 

        <!-- Modal Body --> 
        <div class="modal-body"> 

         <form role="form"> 
          <div class="form-group"> 
          <label for="exampleInputEmail1"></label> 
           <input type="text" class="form-control" 
           id="archiveName" placeholder="Please enter the name for the archive"/> 
          </div> 

         </form> 


        </div> 

        <!-- Modal Footer --> 
        <div class="modal-footer"> 
         <button type="button" class="btn btn-default" 
           data-dismiss="modal"> 
            Close 
         </button> 
         <a href="create_zip.php" class="btn btn-primary"> 
          Download 
         </a> 
        </div> 
       </div> 
      </div> 
     </div>          


    <?php endforeach;?> 

<?php endforeach; ?> 
</table> </div> 

だけでなく、この入力を取るためにどのようにこの<input type="text" class="form-control" id="archiveName" placeholder="Please enter the name for the archive"/>

+0

はどちらかそれをarchiveNameフィールドを渡し、onClickのをcreate_zip.php呼び出すか、クリックイベントにフックと_GETパラメータとしてarchiveNameの値を渡すことができAJAXボタンとしてそれを行います。 – Farkie

+0

どうすればAJAXで作成できますか?create_zip.php onClickを呼び出し、archiveNameフィールドを渡してAJAXボタンとして実行するのはどちらですか? –

答えて

0

これは実際には簡単に実現できます。まず<form></form> の周りにあなたのテーブルを包むのでISSETボタンを提出し、変数を割り当てる場合はそれだけでチェックcreate_zip.phpに続いて、この

if(! isset($_POST['showcart'])) exit; 
echo '<form action="create_zip.php" method="post"> 
     <a class="btn btn-danger btn-lg pull-right" style="margin: 10px;" data-toggle="modal" data-target="#myModalNorm">Download All Files</a> 
     <table class="table table-striped table-bordered table-condensed responsive" id="sort"> 
     <thead> 
      .... 
        <!-- Modal Body --> 
        <div class="modal-body"> 

          <div class="form-group"> 
          <label for="archiveName"></label> 
           <input type="text" class="form-control" 
           id="archiveName" name="archiveName" placeholder="Please enter the name for the archive"/> 
          </div> 

        </div> 
        <!-- Modal Footer --> 
        <div class="modal-footer"> 
         <button type="button" class="btn btn-default" 
           data-dismiss="modal"> 
            Close 

         <input type="submit" name="submit" value="Download" class="btn btn-primary"> 

        </div> 
       </div> 
      </div> 

     </div>          

    <?php endforeach;?> 

<?php endforeach; ?> 
</table> </div></form> 

ような何かが起こるのだろう。

if(isset($_POST['submit'])) 
{ 
    //your code 
    $archiveName = $_POST['archiveName']; 

    // other source 
} else { echo 'no archive'; } 
関連する問題