Hi all, I have a problem when I try to send an array using a form when
the type="checkbox" .
This is my form input row:
<INPUT type="Checkbox" name="flg[]" value="y" <? if($row['flag'] ==
'y') echo 'CHECKED'; ?>>
Since this is an update form, I set the status of the flg[] according
to the field "flag" stored in a MySQL database. The user may check or
uncheck each of the checkboxes on the form.
This form is sent to another PHP file with other fileds of type
<SELECT> and type="Text". Here's the code which process the checkbox
input:
$max_i = count($flg);
for($i=0;$i<$ma x_i;$i++)
{
if($flg[$i] == 'y')
{
$flag = 'y';
}
else
{
$flag = 'n';
}
echo $i.'-->'.$flg[$i].'-->'.$flag.'<BR>' ;
}
I have no problems processing the array associated with the SELECT
and "Text" fileds, but when I try using the Checkbox, this is what I
receive:
0-->y-->y
1-->y-->y
2-->y-->y
3-->y-->y
4-->y-->y
5-->y-->y
Trying with this other code:
$num_of_checkbo x_fileds = 12;
for($i=0;$i<$nu m_of_checkbox_f ileds;$i++)
{
if($flg[$i] == 'y')
{
$flag = 'y';
}
else
{
$flag = 'n';
}
echo $i.'-->'.$flg[$i].'-->'.$flag.'<BR>' ;
}
I receive this output:
0-->y-->y
1-->y-->y
2-->y-->y
3-->y-->y
4-->y-->y
5-->y-->y
6-->-->n
7-->-->n
8-->-->n
9-->-->n
10-->-->n
11-->-->n
The problem is that there is no order in what I receive!!
I have the first elements af the array with a 'y' and the others with
a 'n'.
The correct output, according with the user's input, should be:
0-->n-->n
1-->y-->y
2-->n-->n
3-->y-->y
4-->n-->n
5-->y-->y
6-->n-->n
7-->y-->y
8-->n-->n
9-->y-->y
10-->n-->n
11-->y-->y
Any idea? Please help!!!
Thank You.
the type="checkbox" .
This is my form input row:
<INPUT type="Checkbox" name="flg[]" value="y" <? if($row['flag'] ==
'y') echo 'CHECKED'; ?>>
Since this is an update form, I set the status of the flg[] according
to the field "flag" stored in a MySQL database. The user may check or
uncheck each of the checkboxes on the form.
This form is sent to another PHP file with other fileds of type
<SELECT> and type="Text". Here's the code which process the checkbox
input:
$max_i = count($flg);
for($i=0;$i<$ma x_i;$i++)
{
if($flg[$i] == 'y')
{
$flag = 'y';
}
else
{
$flag = 'n';
}
echo $i.'-->'.$flg[$i].'-->'.$flag.'<BR>' ;
}
I have no problems processing the array associated with the SELECT
and "Text" fileds, but when I try using the Checkbox, this is what I
receive:
0-->y-->y
1-->y-->y
2-->y-->y
3-->y-->y
4-->y-->y
5-->y-->y
Trying with this other code:
$num_of_checkbo x_fileds = 12;
for($i=0;$i<$nu m_of_checkbox_f ileds;$i++)
{
if($flg[$i] == 'y')
{
$flag = 'y';
}
else
{
$flag = 'n';
}
echo $i.'-->'.$flg[$i].'-->'.$flag.'<BR>' ;
}
I receive this output:
0-->y-->y
1-->y-->y
2-->y-->y
3-->y-->y
4-->y-->y
5-->y-->y
6-->-->n
7-->-->n
8-->-->n
9-->-->n
10-->-->n
11-->-->n
The problem is that there is no order in what I receive!!
I have the first elements af the array with a 'y' and the others with
a 'n'.
The correct output, according with the user's input, should be:
0-->n-->n
1-->y-->y
2-->n-->n
3-->y-->y
4-->n-->n
5-->y-->y
6-->n-->n
7-->y-->y
8-->n-->n
9-->y-->y
10-->n-->n
11-->y-->y
Any idea? Please help!!!
Thank You.
Comment