0

If I make a long story very short, I have a short form I've made (an input, a select, and three checkboxes). I've made a function on a button that can dynamically add multiple instances of this form on my page. It saves it as an array (i.e. the input name is name="checkbox[]") which will save fine in my database. The problem I run into is I may have 6 instances of this form, but only some of the boxes are checked. So, I may have 6 text inputs, 6 select inputs, but maybe only 3 checkbox inputs. Since it only has 3 inputs, the array is only 3 pieces of data and when I run a for() statement it doesn't accurately save this information and tie it to the correct record.

I thought that maybe I could have a hidden input that will get its value assigned through javascript, but I don't know how to reference the checkboxes appropriately (you can't do id="blahblah[]" right?)

Sad and Confused,

ImmortalFirefly

2
  • Are you using separate form tags? Commented Apr 22, 2011 at 19:48
  • @Fosco: yes separate form tags. They all have different names, they just apply to the same record. Commented Apr 23, 2011 at 22:36

1 Answer 1

1

I am not sure I have caught your drift on this one, but consider this:

<?php

var_dump( $_POST )

?>

<form name=form0 method= post action = "">
<input type=checkbox name=checkbox[0][0] />
<input type=checkbox name=checkbox[0][1] />
<input type=checkbox name=checkbox[0][2] />
<input type = submit>
</form>

Then another form is added


<form name=form1 method= post action = "">
<input type=checkbox name=checkbox[1][0] />
<input type=checkbox name=checkbox[1][1] />
<input type=checkbox name=checkbox[1][2] />
<input type = submit>
</form>

Mock that up in html and POST it back to a webpage and see how it works, you can iterate through th post value to see which form was sent and which box checked, or put it all in one single form.

<?php

var_dump( $_POST )

?>

<form name=form0 method= post action = "">
<input type=checkbox name=checkbox[0][0] />
<input type=checkbox name=checkbox[0][1] />
<input type=checkbox name=checkbox[0][2] />
<input type = submit>


Then another series of checkboxes is added :



<input type=checkbox name=checkbox[1][0] />
<input type=checkbox name=checkbox[1][1] />
<input type=checkbox name=checkbox[1][2] />

close off the form

<input type = submit>
</form>
Sign up to request clarification or add additional context in comments.

1 Comment

That actually works! I'll have to tweak my page and script, but at this point, I don't necessarily care what I have to do to make it work. Through Javascript, I just add a count to the array numbers every time I add another duplicate form. Works like a charm. Thanks!

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.