I am making an ajax request through a message that contains form variables.
data for ajax request look like
data : { somevar1: 'someval1', somevar2: 'someval2', somevar3: 'someval3', somevar4: 'someval4', form: FORMDATA }
as you can see, as well as the data of the basic form, I also transmit some other data.
this means i cannot use jquery .serialize()
I want to end up with what I can send, so on the other hand I can just do
$_POST['form']['fieldname']
is there a built-in function?
or what do i need to do to create it?
the ability to run a function in a form that does something like
function postArray(form){ var data = {}; var name, value = null; $(form).children('textarea, input, select'){ name = this.name; data.name = $(this).val(); } return data; }
can work on a form.
and having
data : { somevar1: 'someval1', somevar2: 'someval2', somevar3: 'someval3', somevar4: 'someval4', form: postArray(form) }
will it work?
I could use
.serializeArray(); But then again I get
Array ( [0] => Array ( [name] => name1 [value] => val1 ), [1] => Array ( [name] => name2 [value] => val2 ) ... [8] => Array ( [name] => name8 [value] => val8 ) )
Which is close, but it requires me either a: loop over the array and convert it to what I want
b: every time i use it, iterate over it to find the right key