3

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..

asked May 10, 2013 at 19:32
3
  • 2
    Maybe i'm missing somehing, but shouldn't "name: 'cf_'+custoptsids[i]" be instead "name: 'cf['+custoptsids[i]+']'"? Commented May 10, 2013 at 19:35
  • Omg... You are the BEST!!!!!!! Thank you! I can't believe I overlooked that. I guess that's what you get for programming for 9 straight hours x_x Commented May 10, 2013 at 19:42
  • Do you want to go ahead and answer it and I'll mark you answer correct? =) Commented May 10, 2013 at 19:44

1 Answer 1

2

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.

answered May 10, 2013 at 19:53
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you again <333 Yeah I haven't taken my lunch yet, but I'm eating now =) I never seem to take breaks until I get it working, but I should try and do that more often :P

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.