Forum Moderators: coopster

Message Too Old, No Replies

PHP and checkbox arrays

         

Thirt33nth

9:41 pm on May 16, 2010 (gmt 0)

10+ Year Member



Hello,

I have an issue with handling of checkboxes.
My page has textboxes and checkboxes, and they are added with the help of jQuery. They can also be deleted, so I can't assign static values to them.

The page looks in a following way:

[+]
[content 1___] [v] [x]
[content 2___] [ ] [x]
[content 3___] [v] [x]

when I try to read values on the server side, I get the following:

$_POST['textboxes']:
[0] => [content 1]
[1] => [content 2]
[2] => [content 3]

$_POST['checkboxes']:
[0] => [on]
[1] => [on]

I assume that's because checkboxes don't have any values.
Is there any way to get this to work with the server side (PHP) scripting?

I want checkboxes and textboxes to be correlated with each other (for example, to know that fields with content 1 and 3 have checked boxes near to them).

yangball

8:18 am on May 17, 2010 (gmt 0)

10+ Year Member



I am a Chiness , English Very Bad.......

here add input_text and checkbox
function addForm(){
var i=1;//i is index....
document.write('<input type="text" name="txt_'+i+'"/><input type="checkbox" name="chk'+i+'"/>');

}

PHP:

foreach($_POST as $key=>$value){
if(stristr('txt_'))// this is text content... You Can get this Index....
}

Thirt33nth

9:02 am on May 17, 2010 (gmt 0)

10+ Year Member



Thank you very much. Maybe this is the best way. I've already thought about adding textboxes and checkboxes with ordered names instead of arrays.