0

I'm having a really interesting problem with JQuery generated form. The form has a couple of input arrays (name="a[]", name="b[]" and etc.). Everything generates just great! But when I submit the form my php script doesn't return the inputs as arrays but as a string.

I'm copying an existing code and placing it into a visible part. I tried to make the form static - copy/pasted the javascript generated form, saved it and it worked perfectly. Apparently there's something I'm missing and it's coming from JQuery.

My source code is posted here
The php script I'm posting this form doesn't do anything at all - just var_dump($_POST);

1
  • Can you paste the var_dump into the question Commented Mar 15, 2011 at 4:02

2 Answers 2

1

If you want to have all the name/options posted then you should be using two sets of square brackets.

e.g.

option_name[0][] or option_name[0][0]

Anywhere there is a repeated name in a form the last (I believe) is the only value sent in the request.

You have multiple groups being added of the same data, so you are correctly creating arrays for them by using different values in the first square brackets, but the 4 options in each group have exactly the same name, so they are passed through as one value.

Sign up to request clarification or add additional context in comments.

1 Comment

Dooh... Coding in the late hours seems to be a bad thing for me... Thanks for saving me the headache :)
1

$(this).attr('name', "option_name\[" + myContainer.arrayId + "\]");

arrayId is not a property of the myContainer function, it's a global variable. Also, I'm pretty sure you don't need to escape the square brackets inside a string.

1 Comment

You're right. I was experimenting if that was the problem. Thanks for pointing that out :)

Your Answer

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.