Aug 06, 2014; 22:43
Steffan A. Cline
Best Practices - AJAX With Multiple Fields Of The Same Name - Lasso 9
I've been working with serializing forms and submitting over AJAX with
POST.
I use the following code to do so:
$.fn.serializeObject = function(){
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
Example: Form has 20 checkboxes all with the same name "product_id"
When the data is serialized via AJAX and POSTed, with only 1 checkbox you
can access the parameter with 'product_id'
BUT
When multiple checkboxes are checked you have to access the parameters
with 'product_id[]'
Sure, it's possible to do stuff like:
local(products = web_request->param('product_id',false)
|| web_request->param('product_id[]',false)
|| staticarray )
That works fine but there are occasions where it can be bulky.
I thought about adding a method to web_request like ->ajaxparam('product')
that could do this same logic internally but figured someone may have a
better way of doing it and hey, why reinvent the wheel.
What do YOU do?
Thanks
Steffan
---------------------------------------------------------------
T E L 6 0 2 . 7 9 3 . 0 0 1 4 | F A X 6 0 2 . 9 7 1 . 1 6 9 4
Steffan A. Cline Steffan@ExecuChoice.net
http://www.ExecuChoice.net Phoenix, Arizona USA
---------------------------------------------------------------
#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014
#############################################################
This message is sent to you because you are subscribed to
the mailing list Lasso Lasso@lists.lassosoft.com
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <Lasso-unsubscribe@lists.lassosoft.com>
Send administrative queries to <Lasso-request@lists.lassosoft.com>
Aug 07, 2014; 10:07
Jolle Carlestam
Re: Best Practices - AJAX With Multiple Fields Of The Same Name - Lasso 9
Aug 07, 2014; 06:26
Steffan A. Cline
Re: Best Practices - AJAX With Multiple Fields Of The Same Name - Lasso 9
Aug 08, 2014; 09:52
Ke Carlton
Re: Best Practices - AJAX With Multiple Fields Of The Same Name - Lasso 9