0

hi there I have form like this:

<form id="form">
<input type="text" name="fname" />

<input type='checkbox' name='ck[]' value='1'id='ck_1' />
<input type='checkbox' name='ck[]' value='2'id='ck_2' />
<input type='checkbox' name='ck[]' value='3'id='ck_3' />

<button id="btn">send</button>
</form>

I send this form these method via JQuery.

$('body').on('click','#btn',function(event)
{
    event.preventDefault();     
    $.ajax({
        type: "POST",
        url: "index.php",
        data: $("#form").serialize(),
        success: function(data) 
        {
              alert('data sent.');
        }
        ...

now how can I print all post?

I try this:

foreach ($_POST as $key => $value)
        echo "Field ".htmlspecialchars($key)." is ".htmlspecialchars($value)."<br>";

but it not works for multi select checkbox...

how can I access checkbox values in server?

elize
  • 435
  • 1
  • 8
  • 19

1 Answers1

0

As far as I can see from this fiddle: https://jsfiddle.net/jimedelstein/ddrkqruq/ the data is being passed to the server successfully, here's the output:

fname=myname&ck[]=1&ck[]=3

But the values are coming through on the server as an array called ck[]. Checkout this post for more on handling the properly : PHP access all $_POST[] variables into an array?

Community
  • 1
  • 1
Jim Edelstein
  • 792
  • 6
  • 10