Re: [PHP] checkbox validation

2001-04-24 Thread Keyur Kalaria

Hi jacky,

put an empty square bracket after the variable name as follows:
input type=checkbox name=id[ ] value=$id

assuming that your above statement is in a loop we will have following
structure:
*
form
input type=checkbox name=id[ ] value=$id
input type=checkbox name=id[ ] value=$id
input type=checkbox name=id[ ] value=$id
etc...

submit button

/form

now when you submit the form, an array named id[ ] will be posted .
this array will contain the number of elements/checkbox  which were checked
on.
so out of 25 checkboxes if you select only 5 checkboxes, then the size of
the array id[ ] will be only 5.

so with another loop you can retrieve all the values as follows:
***
$i=0;
while($isizeof($id):

$id[$i]==blah;

$i++;

endwhile;
***

sorry for the poor explanation but i hope this will serve your purpose. if
you have any queries with this feel free to contact me.

regards

keyur
$$$


- Original Message -
From: Jacky [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, April 19, 2001 1:13 AM
Subject: [PHP] checkbox validation


Hi all
I have a form with the checkbox like this
form
$query=select id from foo;
$result=($query,$con);
while ($row = mysql_fetch_array($result))
 {
input type=checkbox name=$id value=on
 }
submit button and stuffs here...
/form

After I submit to next page, at next page, how do I check which check box is
checked?
like this?

if ($id==on) {
do something
}else{
do something
}

I did try this but did not work, what am i suppose to do to achieve this?
Jack
[EMAIL PROTECTED]
There is nothing more rewarding than reaching the goal you set for
yourself



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] checkbox validation

2001-04-18 Thread Matt Williams


 After I submit to next page, at next page, how do I check which 
 check box is checked?
 like this?
 
 if ($id=="on") {
 do something
 }else{
 do something
 }

Hi 

try this assuming you have no toher check boxes called $id

if(isset($id))
{
  do something
}else{
  do other
}

M@

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] checkbox validation

2001-04-18 Thread Robert Vetter



Jacky wrote:
 
 Hi all
 I have a form with the checkbox like this
 form
 $query="select id from foo";
 $result=($query,$con);
 while ($row = mysql_fetch_array($result))
  {
 input type="checkbox" name="$id" value="on"
  }
 submit button and stuffs here...
 /form

One possibility:
Add a hidden field in the form and write all names of the checkboxes in
it, separated by a semicolon, for example.
-
form
$query="select id from foo";
$result=($query,$con);
while ($row = mysql_fetch_array($result))
{
input type="checkbox" name="$id" value="on"
$names_of_checkboxes.=$id.";";
}
input type="hidden" name="names_of_checkboxes" value="? echo
$names_of_checkboxes; ?"
 submit button and stuffs here...
 /form
---
Then, in the next page you just do following:
---
$checkboxes_names_array=explode(";",$names_of_checkboxes);
for($x=0;xcount($checkboxes_names_array);$x++)
{
if($$checkboxes_names_array[$x]=="on")
// box checked
}
---

Robert

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]