1

i have a form with some checkboxes. if i activate a ceckbox, jquery is sending the data with the .serialize() function to a php file via ajax. The problem is, that jquery send some double parameters. Here is the Query:

area=26-50&area=51-75&area=76-100&area=100&std=1&std=3

How can i create a array like this:

array( 'area' => array(0 => '26-50',1 => '51-75',2 => '76-100'), std => array(0 => 1,1 => 3) )

PHP overwrites the last variable with a new one...

Thanks for the help!

greetings

2 Answers 2

10

[] notation will make it possible to transmit array data in a form.

Name the checkboxes in the form like this:

<input name="area[]" type="checkbox" value="51-75">

this should build an array of all selected check boxes.

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

Comments

2

PHP can support this if the key name is appended with []:

area[]=26-50&area[]=51-75&area[]=76-100&area[]=100&std[]=1&std[]=3
/*
Array
(
    [area] => Array
        (
            [0] => 26-50
            [1] => 51-75
            [2] => 76-100
            [3] => 100
        )

    [std] => Array
        (
            [0] => 1
            [1] => 3
        )

)
*/

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.