1

I am new in PHP. I have two files. file_upload.php and test1.php i have a button on file_upload.php

<input type="button" value="Link More Opinion" onclick="popUp('test1.php');" />

JavaScript of that Button

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

When i click on Button test1.php file is open in Pop Up window contain checkbox

Here is code

<?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"/>

Now i want to get Value of Checkbox on file_upload.php but i fail. Can anyone please help me?

Thamilhan
  • 13,040
  • 5
  • 37
  • 59
sunny
  • 1,511
  • 5
  • 20
  • 57
  • 2
    Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard May 17 '16 at 12:30
  • @JayBlanchard Thank you I will avoid by using `mysql_` but please help me in my current issue – sunny May 17 '16 at 12:32
  • Have you checked your error logs? – Jay Blanchard May 17 '16 at 12:32
  • Actually i dont have any idea how i get variables from `test.php` to `file_upload.php` using pop up as i asked in my question – sunny May 17 '16 at 12:33
  • When you click the submit button on the for the variables will be available in the `$_POST` array in file_upload.php. – Jay Blanchard May 17 '16 at 12:37
  • Yes I use it `` but not working – sunny May 17 '16 at 12:42
  • There's no point using `implode()` and then `explode()` again. Directly use `$all_opinions` array in your `for` loop. – Rajdeep Paul May 17 '16 at 13:04
  • Do you want to process the form data in the pop up window itself, or do you want a scenario where after user hits the submit button, the pop up window will close so that you could process the form data in `file_upload.php` file? – Rajdeep Paul May 17 '16 at 13:16

1 Answers1

1

you can solve your problem by using fancybox to open inline element!

I put both of your pages in one file and then I use fancy box to open #form1 element when you click on the button.

then you can check the checkboxes and see the result;

checked values printed to #print-values div element.

$(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>
  • Its Working Fine Can you tell me one thing more. I want to pass all values on another page. How i can do it? – sunny May 18 '16 at 06:32
  • you can put the popup div in the form element and then add a submit button to the form. then you shoud change your jquery code. I do everything and put the editted code [here](https://jsfiddle.net/a3dmorteza/j3g97jv1/) just for you ;) don't forget to replace the action attribute of form element whit the correct form processor url. – Seyed Morteza Hosseini May 18 '16 at 23:08