I have a list with three things, first a title for the entire list, then a user can add categories with questions below each category dynamically.
I need to add these lists to my database and currently have this array when posting (using ajax with serializeArray ):
Array
(
[0] => Array
(
[name] => lijsttitle
[value] => Title
)
[1] => Array
(
[name] => category[]
[value] => category 1
)
[2] => Array
(
[name] => question[]
[value] => question 1
)
[3] => Array
(
[name] => question[]
[value] => question 2
)
[4] => Array
(
[name] => question[]
[value] => question 3
)
[5] => Array
(
[name] => category[]
[value] => category 2
)
[6] => Array
(
[name] => question[]
[value] => question 1
)
[7] => Array
(
[name] => question[]
[value] => question 2
)
)
All questions and categories are already in the correct order but I want them grouped together, something like this:
Array
(
[title] => Array
(
[value] => Title
)
[category 1] => Array
(
[question] => question 1
[question] => question 2
[question] => question 3
)
[category 2] => Array
(
[question] => question 1
[question] => question 2
)
)
Or maybe another way if there is a better one.
I serialize my form like this:
$( ".lijstbutton" ).on( "click", function( event ) {
event.preventDefault();
url = 'includes/createlist.php';
$lijst = $( '#lijstform' ).serializeArray();
var posting = $.post(url, {lijst: $lijst});
posting.done(function( data ) {
$( ".lijstresult" ).empty().slideDown('fast').append( data );
});
});
And to show my current array I have this code in createlist.php :
echo '<pre>';
print_r($_POST['lijst']);
echo '</pre>';
In the end I need all questions linked to a category and all categories linked to the title of the entire list.
So you can have multiple lists each with their categories and questions below those categories.
[]after the name of the input fields, but in my array there is nothing added, just the empty[][{"name":"lijsttitle","value":"sdg"},{"name":"category[]","value":"dsg"},{"name":"question[]","value":"dsgsd"},{"name":"category[]","value":"gsdgsd"},{"name":"question[]","value":"gsd"}]