user275241
user275241

Reputation:

Multidimensional JavaScript Array to PHP Array

I have been trying to figure this out for awhile. I have a multidimensional array in JavaScript that is 12 columns wide and an unknown number of rows like so

/*
[
    [userID (int), name, username, email, password, other 1, other 2, other 3, other 4, other 5, other 6, admin(int)],
    [userID (int), name, username, email, password, other 1, other 2, other 3, other 4, other 5, other 6, admin(int)],
    [userID (int), name, username, email, password, other 1, other 2, other 3, other 4, other 5, other 6, admin(int)],
    ...
]
*/

All the values are string except the (int) ones. This is for a real time user editing page for my site. I have the JavaScript array made now I need it so when the "Submit" button is pressed it turns the array formated like that into an PHP array and saves it as a variable. Can I get some help?

Upvotes: 2

Views: 520

Answers (2)

DisgruntledGoat
DisgruntledGoat

Reputation: 72510

What you need to do is add the data to hidden fields in your form, if they are not already regular input fields.

You probably want to use field naming like this:

<input type="hidden" name="data[100][username]" value="myusername" />
<input type="hidden" name="data[100][email]" value="[email protected]" />

Where 100 is whatever each user id is.

Upvotes: 0

Gordon
Gordon

Reputation: 316969

Encode to JSON, post to PHP via Ajax or regular Form and decode on the serverside with json_decode

Upvotes: 6

Related Questions