Reputation: 3295
Ok I'm trying to append data to an existing form when someone submits it.
function submitCustOpts() {
var custoptsids=new Array(".implode(",",$optids).");
var pfrm=document.forms['promotion".$promo_data["promo_id"]."'];
for(var i in custoptsids) {
selectedVal = $('#'+custoptsids[i]).val();
var input = $('<input>').attr(
{
type: 'hidden',
name: 'cf_'+custoptsids[i],
value: selectedVal
}).appendTo(pfrm);
}
pfrm.submit();
}
EVERYTHING works. So just ignore the first half. The part I can not get it the appending to the form. The custoptsids[i] holds the id and the selectedVal holds the value. It's all working dandy, but I need to put this in a multidimensional array. Right now it submits like this:
<!-- REQUEST: Array
(
[promo_id] => 164792
[station_id] => 2478
[lang] => en
[cf_28] => 55
[cf_29] => 61
[PHPSESSID] => 375ee178f5de3blahblahblah
)
-->
When it should look like this:
<!-- REQUEST: Array
(
[promo_id] => 164792
[station_id] => 2478
[lang] => en
[cf] => Array
(
[28] => 55
[29] => 60
)
[PHPSESSID] => 375ee178f5de3blahblahblah
)
-->
So my question is how do I put those values into the cf array.. cf_28 should be just cf with 28 and 29 as the array keys for the inner array..
Upvotes: 3
Views: 1903
Reputation: 1295
I'm happy to help, also if you were really a step from the "solution". The solution would be "pause for a while", "have a coffee/tea", go back to code. But anyway:
var input = $('<input>').attr(
{
type: 'hidden',
// name: 'cf_'+custoptsids[i], <- look twice :)
name: 'cf['+custoptsids[i]+']',
value: selectedVal
}).appendTo(pfrm);
Its the same for me. EVERY time. Glad I could help.
Upvotes: 2