javascript - Passing multiple form data to PHP controller -



javascript - Passing multiple form data to PHP controller -

$('#save').on("click", function() { //collect form info while iterating on inputs var info = []; $('[name=form]').find('input, select, textarea').each(function() { if ($(this).attr('value') != '') { var name = $(this).attr('name'); var value = $(this).attr('value'); data[name] = value; } }) (var = 1, ii = form.length; < ii; i++) { var name = 'form' + i; $('[name=' + name + ']').find('input, textarea').each(function() { data[i] = []; if ($(this).attr('value') != '') { var name = $(this).attr('name'); var value = $(this).attr('value'); data[i][name] = value; } }) } $.post('foo', data, function(data) { console.log(data);

i have above jquery code wish post multiple form info php backend controller.

in controller, used

$input = input::all()

question 1

how access info in array have passed? let's have foo input , bar input in form. tried use

$input['foo'] $input['bar']

but i'm getting internal server error undefined index error.

question 2

how access info of data[i][name]? let's have form1, form2, form3, info array become

$data[1][foo] $data[2][foo] $data[3][foo]

how can access these in php controller?

thanks , sorry long question

with formdata object.

var formdata = new formdata(); formdata.append("name", value);

on server-side read values this:

$name = $_post["name"];

javascript php jquery arrays

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -