如何在PHP中使用Pop Ups获取变量?

时间:2016-05-17 12:25:10

标签: javascript php jquery

我是PHP新手。我有两个文件。 file_upload.phptest1.php file_upload.php

上有一个按钮
<input type="button" value="Link More Opinion" onclick="popUp('test1.php');" />

该按钮的JavaScript

<script type="text/javascript">
function popUp(url) {
window.open(url,'PHP Pop Up','width=500,height=500');
}
</script>

当我点击按钮test1.php时,弹出窗口中的文件包含复选框

这是代码

<?php

include "connection.php";
$sql= "SELECT * FROM `og_companies` ORDER BY name";
$result  = mysql_query($sql) ;

while($row = mysql_fetch_array($result))
{
    $all_opinions[] = $row['name'];
}
$all_opinions_implode = implode(",", $all_opinions);

$all_opinions_explode = explode (",", $all_opinions_implode);
?>
<form action="file_upload.php" id="form" method="post" name="form">
    <?php

    for ($i=0; $i<count($all_opinions_explode); $i++) {
        echo    "<input type='checkbox' name='test_link' > $all_opinions_explode[$i]";
        //echo ;
        echo'</br>';    
    }
    ?>
    <input type="submit" name="submit" id="submit" value="submit"/>

现在我想在file_upload.php上获得Checkbox的价值,但我失败了。有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:1)

您可以使用fancybox打开内联元素来解决您的问题!

我把你的两个页面都放在一个文件中,然后当你点击按钮时我使用花式框来打开#form1元素。

然后您可以选中复选框并查看结果;

检查打印到#print-values div元素的值。

$(document)
  .ready(function() {
    $(".various").fancybox({
      maxWidth: 800,
      maxHeight: 600,
      fitToView: false,
      width: '70%',
      height: '70%',
      autoSize: false,
      closeClick: false,
      openEffect: 'none',
      closeEffect: 'none'
    });

    $('.button1').click(function(e) {
      e.preventDefault();
      $('.various').click();
    });

  })
  .on('change', '[name=test-link]', function() {
    $('#print-values').empty();
    $('#print-values').append("<span>You've checked:</span><br />");
    $('[name=test-link]').each(function() {
      if ($(this).prop("checked")) {
        var v = $(this).val();
        $('#print-values').append(v + "<br />");
      }
    });
  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.pack.js"></script>

<a class="various" href="#form1" style='display: none;'></a>
<input class='button1' type="button" value="Link More Opinion" />
<div id='print-values'></div>
<div style='display: none;'>
  <form id='form1'>
    <input type='checkbox' name='test-link' value="1" />
    <span>1</span>
    <br />
    <input type='checkbox' name='test-link' value="2" />
    <span>2</span>
    <br />
    <input type='checkbox' name='test-link' value="3" />
    <span>3</span>
    <br />
  </form>
</div>