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?

3
  • Is it working for other fields like textbox? Commented Feb 17, 2016 at 13:12
  • yes,If I remove checkbox,it works for all others like radio,text,select... Commented Feb 17, 2016 at 13:23
  • Actually checkbox is an array while you getting elements in php. So do add condition in loop for checkbox. If found checkbox print array so you will get all value of it. Commented Feb 17, 2016 at 13:25

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.