[PHP-DB] HTML Forms question...

2002-11-19 Thread NIPP, SCOTT V (SBCSI)
I know that this is not the forum for this question, I am only
looking for a pointer in the right direction here.  I need to gain a better
understanding of HTML forms, specifically checkboxes.  What I am looking for
is once I present a list of checkboxes and the user makes his selections,
how is this presented to the subsequent pages?  Does anyone know of a
website that has a tutorial or good explanation of how this works?  Thanks
in advance.

Scott Nipp
Phone:  (214) 858-1289
E-mail:  [EMAIL PROTECTED]
Web:  http:\\ldsa.sbcld.sbc.com



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] HTML Forms question...

2002-11-19 Thread Ryan Jameson (USA)
input type=checkbox name=checkbox1 value=scoobydoo

if this is checked the value scoobydoo will be put into the array with index 
checkbox1 which array is dependant on which method your form uses. :-) If it is not 
checked then there is no entry. in PHP with register_globals on the variable 
$checkbox1 will equal scoobydoo and not be set if the box is not checked.

hope this helps...

 Ryan

-Original Message-
From: NIPP, SCOTT V (SBCSI) [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 19, 2002 9:28 AM
To: '[EMAIL PROTECTED]'
Subject: [PHP-DB] HTML Forms question...


I know that this is not the forum for this question, I am only
looking for a pointer in the right direction here.  I need to gain a better
understanding of HTML forms, specifically checkboxes.  What I am looking for
is once I present a list of checkboxes and the user makes his selections,
how is this presented to the subsequent pages?  Does anyone know of a
website that has a tutorial or good explanation of how this works?  Thanks
in advance.

Scott Nipp
Phone:  (214) 858-1289
E-mail:  [EMAIL PROTECTED]
Web:  http:\\ldsa.sbcld.sbc.com



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] HTML Forms question...

2002-11-19 Thread NIPP, SCOTT V (SBCSI)
OK.  If I am using the POST method and the checkbox 'name' for all
of the checkboxes is 'system', how do I access the results?  I am
researching on the PHP site trying to figure out what this array is, and how
I access this if the index name is the same for all elements.  I am hoping
that this data will be in an array and I can simply loop through the
contents of the array.  If this data is stored in a hash (Perl word for this
type of array, not sure if it's the same in PHP), how do I access this data
since the index for every element would be the same?
I am SURE that I am probably missing some important conceptual
issues here, but still learning as I go.  Unfortunately, this probably means
that I will be completely rewriting this application at least once in the
future.  Oh well, live and learn.  Thanks again for the help.

-Original Message-
From: Ryan Jameson (USA) [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 19, 2002 10:35 AM
To: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] HTML Forms question...


input type=checkbox name=checkbox1 value=scoobydoo

if this is checked the value scoobydoo will be put into the array with
index checkbox1 which array is dependant on which method your form uses.
:-) If it is not checked then there is no entry. in PHP with
register_globals on the variable $checkbox1 will equal scoobydoo and not
be set if the box is not checked.

hope this helps...

 Ryan

-Original Message-
From: NIPP, SCOTT V (SBCSI) [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 19, 2002 9:28 AM
To: '[EMAIL PROTECTED]'
Subject: [PHP-DB] HTML Forms question...


I know that this is not the forum for this question, I am only
looking for a pointer in the right direction here.  I need to gain a better
understanding of HTML forms, specifically checkboxes.  What I am looking for
is once I present a list of checkboxes and the user makes his selections,
how is this presented to the subsequent pages?  Does anyone know of a
website that has a tutorial or good explanation of how this works?  Thanks
in advance.

Scott Nipp
Phone:  (214) 858-1289
E-mail:  [EMAIL PROTECTED]
Web:  http:\\ldsa.sbcld.sbc.com



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] HTML Forms question...

2002-11-19 Thread 1LT John W. Holmes
 OK.  If I am using the POST method and the checkbox 'name' for all
 of the checkboxes is 'system', how do I access the results?  I am
 researching on the PHP site trying to figure out what this array is, and
how
 I access this if the index name is the same for all elements.  I am hoping
 that this data will be in an array and I can simply loop through the
 contents of the array.  If this data is stored in a hash (Perl word for
this
 type of array, not sure if it's the same in PHP), how do I access this
data
 since the index for every element would be the same?
 I am SURE that I am probably missing some important conceptual
 issues here, but still learning as I go.  Unfortunately, this probably
means
 that I will be completely rewriting this application at least once in the
 future.  Oh well, live and learn.  Thanks again for the help.

If you have multiple checkboxes with the same 'name' then you should name
then with brackets, [], such as 'system[]'. This will tell PHP to make the
results an array when the form is submitted.

For any of the 'submit[]' checkboxes that are checked, they will be present
in PHP array on the processing page. Those unchecked will not be present.

Say you have the following.

input type=checkbox name=submit[] value=1One
input type=checkbox name=submit[] value=2Two
input type=checkbox name=submit[] value=3Three

If the method on your form is POST, and the user checks One and Three, then
you'll have the following values in PHP on the ACTION page of the FORM.

$_POST['submit'][0] == 1
$_POST['submit'][1] == 3

From that data, though, there's no way to tell that checkbox Two was not
checked, unless you go through and check all of the values. That's fine for
small forms, but a hassle for large ones.

You could also name your checkboxes like this:

input type=checkbox name=submit[1] value=1One
input type=checkbox name=submit[2] value=2Two
input type=checkbox name=submit[3] value=3Three

and if the user checks one and three again, you'll get

$_POST['submit'][1] == 1
$_POST['submit'][3] == 3

Hopefully that clears some things up. If you have any other questions, just
ask.

---John Holmes...


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] HTML Forms question...

2002-11-19 Thread Rich Gray
If you name the checkbox as name=system[] then PHP will automatically
create an array of the checkbox values which can be subsequently accessed
via $_POST['system'][n] - be warned however that the '[]' can screw up any
JavaScript code that refers to the checkbox object...

HTH
Rich
-Original Message-
From: NIPP, SCOTT V (SBCSI) [mailto:[EMAIL PROTECTED]]
Sent: 19 November 2002 08:53
To: 'Ryan Jameson (USA)'; [EMAIL PROTECTED]
Subject: RE: [PHP-DB] HTML Forms question...


OK.  If I am using the POST method and the checkbox 'name' for all
of the checkboxes is 'system', how do I access the results?  I am
researching on the PHP site trying to figure out what this array is, and how
I access this if the index name is the same for all elements.  I am hoping
that this data will be in an array and I can simply loop through the
contents of the array.  If this data is stored in a hash (Perl word for this
type of array, not sure if it's the same in PHP), how do I access this data
since the index for every element would be the same?
I am SURE that I am probably missing some important conceptual
issues here, but still learning as I go.  Unfortunately, this probably means
that I will be completely rewriting this application at least once in the
future.  Oh well, live and learn.  Thanks again for the help.


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] HTML Forms question...

2002-11-19 Thread Ryan Jameson (USA)
You learn something new every day! I'll have to remember the [] thing.
My way of handling this situation that does not screw up JavaScript is to assign the 
names sequentially, so instead of all the checkboxes being system they would be 
system0,system1,... Since PHP is so wonderfully easy to use for referencing variable 
variable names I simply loop through:

for($i=0;$iNUMBEROFCHECKBOXES;$i++){
  $var = system$i;
  $val = $$var;
  if (isset($$var)) //--- I think this works.
echo $var = $valbr;
  else
echo $var is not checked.;
}

Since I always end up creating the form in PHP I just have the algorithm put a hidden 
field in the form that contains the number of checkboxes, in fact my PHP usually 
creates the JavaScript code as well, so it ends up being pretty flexible.

 Ryan


-Original Message-
From: Rich Gray [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 19, 2002 6:13 PM
To: NIPP, SCOTT V (SBCSI); [EMAIL PROTECTED]
Subject: RE: [PHP-DB] HTML Forms question...


If you name the checkbox as name=system[] then PHP will automatically
create an array of the checkbox values which can be subsequently accessed
via $_POST['system'][n] - be warned however that the '[]' can screw up any
JavaScript code that refers to the checkbox object...

HTH
Rich
-Original Message-
From: NIPP, SCOTT V (SBCSI) [mailto:[EMAIL PROTECTED]]
Sent: 19 November 2002 08:53
To: 'Ryan Jameson (USA)'; [EMAIL PROTECTED]
Subject: RE: [PHP-DB] HTML Forms question...


OK.  If I am using the POST method and the checkbox 'name' for all
of the checkboxes is 'system', how do I access the results?  I am
researching on the PHP site trying to figure out what this array is, and how
I access this if the index name is the same for all elements.  I am hoping
that this data will be in an array and I can simply loop through the
contents of the array.  If this data is stored in a hash (Perl word for this
type of array, not sure if it's the same in PHP), how do I access this data
since the index for every element would be the same?
I am SURE that I am probably missing some important conceptual
issues here, but still learning as I go.  Unfortunately, this probably means
that I will be completely rewriting this application at least once in the
future.  Oh well, live and learn.  Thanks again for the help.


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] HTML Forms question...

2002-11-19 Thread Ford, Mike [LSS]
 -Original Message-
 From: Rich Gray [mailto:[EMAIL PROTECTED]]
 Sent: 20 November 2002 01:13
 
 If you name the checkbox as name=system[] then PHP will 
 automatically
 create an array of the checkbox values which can be 
 subsequently accessed
 via $_POST['system'][n] - be warned however that the '[]' can 
 screw up any
 JavaScript code that refers to the checkbox object...

G' -- not this old chestnut again!

It only screws up your JavaScript if you don't write your JavaScript to
allow for it.

It's really very simple: *by* *definition* in JavaScript, the notation

a.b

is *identical* to

a[b]

Thus, if you have a single checkbox named with name=system, then you can
access it in either of these ways:

document.form.system
document.form[system]

By extension, if you have multiple checkboxes all named with
name=system[], you can refer to them as:

document.form[system[]][0]
document.form[system[]][1]
document.form[system[]][2]

etc...

I know this works because I've been using it for years (even before I
started programming with PHP!).

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] HTML Forms question...

2002-11-19 Thread Hutchins, Richard
Not only does Mike's description below work really well for a single page,
if you write all of your JS stuff like this, you can very easily use the
same script on multiple pages. Portability! Works great for me.

 -Original Message-
 From: Ford, Mike [LSS] [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, November 19, 2002 1:35 PM
 To: 'Rich Gray'; NIPP, SCOTT V (SBCSI); [EMAIL PROTECTED]
 Subject: RE: [PHP-DB] HTML Forms question...
 
 
  -Original Message-
  From: Rich Gray [mailto:[EMAIL PROTECTED]]
  Sent: 20 November 2002 01:13
  
  If you name the checkbox as name=system[] then PHP will 
  automatically
  create an array of the checkbox values which can be 
  subsequently accessed
  via $_POST['system'][n] - be warned however that the '[]' can 
  screw up any
  JavaScript code that refers to the checkbox object...
 
 G' -- not this old chestnut again!
 
 It only screws up your JavaScript if you don't write your 
 JavaScript to
 allow for it.
 
 It's really very simple: *by* *definition* in JavaScript, the notation
 
 a.b
 
 is *identical* to
 
 a[b]
 
 Thus, if you have a single checkbox named with name=system, 
 then you can
 access it in either of these ways:
 
 document.form.system
 document.form[system]
 
 By extension, if you have multiple checkboxes all named with
 name=system[], you can refer to them as:
 
 document.form[system[]][0]
 document.form[system[]][1]
 document.form[system[]][2]
 
 etc...
 
 I know this works because I've been using it for years (even before I
 started programming with PHP!).
 
 Cheers!
 
 Mike
 
 -
 Mike Ford,  Electronic Information Services Adviser,
 Learning Support Services, Learning  Information Services,
 JG125, James Graham Building, Leeds Metropolitan University,
 Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
 Email: [EMAIL PROTECTED]
 Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 
 
 -- 
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] HTML Forms question...

2002-11-19 Thread Hutchins, Richard
Let me append my earlier post.

If you write a function like this:

function myfunction(name){
document.form.name.do_something_legal_to_this_object
}

All you have to do on subsequent pages is pass the name of the object into
the function and you're good to go (e.g.
onClick=javascript:myfunction(objectName)) as long as the function is
included in the page.

Sorry for any confusion.

 -Original Message-
 From: Hutchins, Richard [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, November 19, 2002 1:45 PM
 To: [EMAIL PROTECTED]
 Subject: RE: [PHP-DB] HTML Forms question...
 
 
 Not only does Mike's description below work really well for a 
 single page,
 if you write all of your JS stuff like this, you can very 
 easily use the
 same script on multiple pages. Portability! Works great for me.
 
  -Original Message-
  From: Ford, Mike [LSS] [mailto:[EMAIL PROTECTED]]
  Sent: Tuesday, November 19, 2002 1:35 PM
  To: 'Rich Gray'; NIPP, SCOTT V (SBCSI); [EMAIL PROTECTED]
  Subject: RE: [PHP-DB] HTML Forms question...
  
  
   -Original Message-
   From: Rich Gray [mailto:[EMAIL PROTECTED]]
   Sent: 20 November 2002 01:13
   
   If you name the checkbox as name=system[] then PHP will 
   automatically
   create an array of the checkbox values which can be 
   subsequently accessed
   via $_POST['system'][n] - be warned however that the '[]' can 
   screw up any
   JavaScript code that refers to the checkbox object...
  
  G' -- not this old chestnut again!
  
  It only screws up your JavaScript if you don't write your 
  JavaScript to
  allow for it.
  
  It's really very simple: *by* *definition* in JavaScript, 
 the notation
  
  a.b
  
  is *identical* to
  
  a[b]
  
  Thus, if you have a single checkbox named with name=system, 
  then you can
  access it in either of these ways:
  
  document.form.system
  document.form[system]
  
  By extension, if you have multiple checkboxes all named with
  name=system[], you can refer to them as:
  
  document.form[system[]][0]
  document.form[system[]][1]
  document.form[system[]][2]
  
  etc...
  
  I know this works because I've been using it for years 
 (even before I
  started programming with PHP!).
  
  Cheers!
  
  Mike
  
  
 -
  Mike Ford,  Electronic Information Services Adviser,
  Learning Support Services, Learning  Information Services,
  JG125, James Graham Building, Leeds Metropolitan University,
  Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
  Email: [EMAIL PROTECTED]
  Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 
  
  -- 
  PHP Database Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
  
 
 -- 
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DB] HTML Forms question...

2002-11-19 Thread Ignatius Reilly
Great piece of advice Mike. Thanks. Far from obvious. I was stuck with this
problem since a few days.

Will that also apply to n-dimensional array, like:
document.form[system[]][0][1] ?

Ignatius

- Original Message -
From: Ford, Mike [LSS] [EMAIL PROTECTED]
To: 'Rich Gray' [EMAIL PROTECTED]; NIPP, SCOTT V (SBCSI)
[EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Tuesday, November 19, 2002 7:35 PM
Subject: RE: [PHP-DB] HTML Forms question...


  -Original Message-
  From: Rich Gray [mailto:[EMAIL PROTECTED]]
  Sent: 20 November 2002 01:13
 
  If you name the checkbox as name=system[] then PHP will
  automatically
  create an array of the checkbox values which can be
  subsequently accessed
  via $_POST['system'][n] - be warned however that the '[]' can
  screw up any
  JavaScript code that refers to the checkbox object...

 G' -- not this old chestnut again!

 It only screws up your JavaScript if you don't write your JavaScript to
 allow for it.

 It's really very simple: *by* *definition* in JavaScript, the notation

 a.b

 is *identical* to

 a[b]

 Thus, if you have a single checkbox named with name=system, then you can
 access it in either of these ways:

 document.form.system
 document.form[system]

 By extension, if you have multiple checkboxes all named with
 name=system[], you can refer to them as:

 document.form[system[]][0]
 document.form[system[]][1]
 document.form[system[]][2]

 etc...

 I know this works because I've been using it for years (even before I
 started programming with PHP!).

 Cheers!

 Mike

 -
 Mike Ford,  Electronic Information Services Adviser,
 Learning Support Services, Learning  Information Services,
 JG125, James Graham Building, Leeds Metropolitan University,
 Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
 Email: [EMAIL PROTECTED]
 Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211

 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] HTML Forms question...

2002-11-19 Thread NIPP, SCOTT V (SBCSI)
Javascript...  What's that???

Just kidding.  I know what it is, but that is about the extent of my
knowledge.  Thanks for all the great feedback.  I was actually just looking
to be pointed in the right direction as this was a bit outside the scope of
this group.  You guys come through in shining fashion though and solve the
problem for me.

Now just to figure out the next 73 issues/steps/challenges/problems.
:)

-Original Message-
From: Ryan Jameson (USA) [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 19, 2002 11:44 AM
To: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] HTML Forms question...


You learn something new every day! I'll have to remember the [] thing.
My way of handling this situation that does not screw up JavaScript is to
assign the names sequentially, so instead of all the checkboxes being system
they would be system0,system1,... Since PHP is so wonderfully easy to use
for referencing variable variable names I simply loop through:

for($i=0;$iNUMBEROFCHECKBOXES;$i++){
  $var = system$i;
  $val = $$var;
  if (isset($$var)) //--- I think this works.
echo $var = $valbr;
  else
echo $var is not checked.;
}

Since I always end up creating the form in PHP I just have the algorithm put
a hidden field in the form that contains the number of checkboxes, in fact
my PHP usually creates the JavaScript code as well, so it ends up being
pretty flexible.

 Ryan


-Original Message-
From: Rich Gray [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 19, 2002 6:13 PM
To: NIPP, SCOTT V (SBCSI); [EMAIL PROTECTED]
Subject: RE: [PHP-DB] HTML Forms question...


If you name the checkbox as name=system[] then PHP will automatically
create an array of the checkbox values which can be subsequently accessed
via $_POST['system'][n] - be warned however that the '[]' can screw up any
JavaScript code that refers to the checkbox object...

HTH
Rich
-Original Message-
From: NIPP, SCOTT V (SBCSI) [mailto:[EMAIL PROTECTED]]
Sent: 19 November 2002 08:53
To: 'Ryan Jameson (USA)'; [EMAIL PROTECTED]
Subject: RE: [PHP-DB] HTML Forms question...


OK.  If I am using the POST method and the checkbox 'name' for all
of the checkboxes is 'system', how do I access the results?  I am
researching on the PHP site trying to figure out what this array is, and how
I access this if the index name is the same for all elements.  I am hoping
that this data will be in an array and I can simply loop through the
contents of the array.  If this data is stored in a hash (Perl word for this
type of array, not sure if it's the same in PHP), how do I access this data
since the index for every element would be the same?
I am SURE that I am probably missing some important conceptual
issues here, but still learning as I go.  Unfortunately, this probably means
that I will be completely rewriting this application at least once in the
future.  Oh well, live and learn.  Thanks again for the help.


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] HTML Forms question...

2002-11-19 Thread NIPP, SCOTT V (SBCSI)
OK.  This has been most helpful, but now I am getting something
strange.  The first element of the array of data is behaving strangely.  For
the code snippet below I am not getting the first selected element
displayed:

?php
... Some stuff snipped...
$a = 0;
?
?php
  while (isset($_POST['system'][$a])) { 
$a++;
echo $_POST['system'][$a];
  }
?

The second, third, and so forth selections all print, just not the
first one.  Also, I can test the contents of the first element by placing an
echo before the while loop.  Thanks in advance.


-Original Message-
From: 1LT John W. Holmes [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 19, 2002 11:11 AM
To: NIPP, SCOTT V (SBCSI); 'Ryan Jameson (USA)'; [EMAIL PROTECTED]
Subject: Re: [PHP-DB] HTML Forms question...


 OK.  If I am using the POST method and the checkbox 'name' for all
 of the checkboxes is 'system', how do I access the results?  I am
 researching on the PHP site trying to figure out what this array is, and
how
 I access this if the index name is the same for all elements.  I am hoping
 that this data will be in an array and I can simply loop through the
 contents of the array.  If this data is stored in a hash (Perl word for
this
 type of array, not sure if it's the same in PHP), how do I access this
data
 since the index for every element would be the same?
 I am SURE that I am probably missing some important conceptual
 issues here, but still learning as I go.  Unfortunately, this probably
means
 that I will be completely rewriting this application at least once in the
 future.  Oh well, live and learn.  Thanks again for the help.

If you have multiple checkboxes with the same 'name' then you should name
then with brackets, [], such as 'system[]'. This will tell PHP to make the
results an array when the form is submitted.

For any of the 'submit[]' checkboxes that are checked, they will be present
in PHP array on the processing page. Those unchecked will not be present.

Say you have the following.

input type=checkbox name=submit[] value=1One
input type=checkbox name=submit[] value=2Two
input type=checkbox name=submit[] value=3Three

If the method on your form is POST, and the user checks One and Three, then
you'll have the following values in PHP on the ACTION page of the FORM.

$_POST['submit'][0] == 1
$_POST['submit'][1] == 3

From that data, though, there's no way to tell that checkbox Two was not
checked, unless you go through and check all of the values. That's fine for
small forms, but a hassle for large ones.

You could also name your checkboxes like this:

input type=checkbox name=submit[1] value=1One
input type=checkbox name=submit[2] value=2Two
input type=checkbox name=submit[3] value=3Three

and if the user checks one and three again, you'll get

$_POST['submit'][1] == 1
$_POST['submit'][3] == 3

Hopefully that clears some things up. If you have any other questions, just
ask.

---John Holmes...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] HTML Forms question...

2002-11-19 Thread Hutchins, Richard
I think it's because you're incrementing $a BEFORE you echo it out. That
would cause your echo statement to start at the second item [1].

 -Original Message-
 From: NIPP, SCOTT V (SBCSI) [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, November 19, 2002 3:36 PM
 To: '1LT John W. Holmes'; 'Ryan Jameson (USA)'; [EMAIL PROTECTED]
 Subject: RE: [PHP-DB] HTML Forms question...
 
 
   OK.  This has been most helpful, but now I am getting something
 strange.  The first element of the array of data is behaving 
 strangely.  For
 the code snippet below I am not getting the first selected element
 displayed:
 
 ?php
 ... Some stuff snipped...
 $a = 0;
 ?
 ?php
   while (isset($_POST['system'][$a])) { 
 $a++;
   echo $_POST['system'][$a];
   }
 ?
 
   The second, third, and so forth selections all print, 
 just not the
 first one.  Also, I can test the contents of the first 
 element by placing an
 echo before the while loop.  Thanks in advance.
 
 
 -Original Message-
 From: 1LT John W. Holmes [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, November 19, 2002 11:11 AM
 To: NIPP, SCOTT V (SBCSI); 'Ryan Jameson (USA)'; [EMAIL PROTECTED]
 Subject: Re: [PHP-DB] HTML Forms question...
 
 
  OK.  If I am using the POST method and the checkbox 'name' for all
  of the checkboxes is 'system', how do I access the results?  I am
  researching on the PHP site trying to figure out what this 
 array is, and
 how
  I access this if the index name is the same for all 
 elements.  I am hoping
  that this data will be in an array and I can simply loop through the
  contents of the array.  If this data is stored in a hash 
 (Perl word for
 this
  type of array, not sure if it's the same in PHP), how do I 
 access this
 data
  since the index for every element would be the same?
  I am SURE that I am probably missing some important conceptual
  issues here, but still learning as I go.  Unfortunately, 
 this probably
 means
  that I will be completely rewriting this application at 
 least once in the
  future.  Oh well, live and learn.  Thanks again for the help.
 
 If you have multiple checkboxes with the same 'name' then you 
 should name
 then with brackets, [], such as 'system[]'. This will tell 
 PHP to make the
 results an array when the form is submitted.
 
 For any of the 'submit[]' checkboxes that are checked, they 
 will be present
 in PHP array on the processing page. Those unchecked will not 
 be present.
 
 Say you have the following.
 
 input type=checkbox name=submit[] value=1One
 input type=checkbox name=submit[] value=2Two
 input type=checkbox name=submit[] value=3Three
 
 If the method on your form is POST, and the user checks One 
 and Three, then
 you'll have the following values in PHP on the ACTION page of 
 the FORM.
 
 $_POST['submit'][0] == 1
 $_POST['submit'][1] == 3
 
 From that data, though, there's no way to tell that checkbox 
 Two was not
 checked, unless you go through and check all of the values. 
 That's fine for
 small forms, but a hassle for large ones.
 
 You could also name your checkboxes like this:
 
 input type=checkbox name=submit[1] value=1One
 input type=checkbox name=submit[2] value=2Two
 input type=checkbox name=submit[3] value=3Three
 
 and if the user checks one and three again, you'll get
 
 $_POST['submit'][1] == 1
 $_POST['submit'][3] == 3
 
 Hopefully that clears some things up. If you have any other 
 questions, just
 ask.
 
 ---John Holmes...
 
 -- 
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] HTML Forms question...

2002-11-19 Thread NIPP, SCOTT V (SBCSI)
DUH!!!  I'm an idiot.  That was quite obvious.  Thanks.  Sorry for
the stupid question.

-Original Message-
From: Hutchins, Richard [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 19, 2002 2:40 PM
To: NIPP, SCOTT V (SBCSI); [EMAIL PROTECTED]
Subject: RE: [PHP-DB] HTML Forms question...


I think it's because you're incrementing $a BEFORE you echo it out. That
would cause your echo statement to start at the second item [1].

 -Original Message-
 From: NIPP, SCOTT V (SBCSI) [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, November 19, 2002 3:36 PM
 To: '1LT John W. Holmes'; 'Ryan Jameson (USA)'; [EMAIL PROTECTED]
 Subject: RE: [PHP-DB] HTML Forms question...
 
 
   OK.  This has been most helpful, but now I am getting something
 strange.  The first element of the array of data is behaving 
 strangely.  For
 the code snippet below I am not getting the first selected element
 displayed:
 
 ?php
 ... Some stuff snipped...
 $a = 0;
 ?
 ?php
   while (isset($_POST['system'][$a])) { 
 $a++;
   echo $_POST['system'][$a];
   }
 ?
 
   The second, third, and so forth selections all print, 
 just not the
 first one.  Also, I can test the contents of the first 
 element by placing an
 echo before the while loop.  Thanks in advance.
 
 
 -Original Message-
 From: 1LT John W. Holmes [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, November 19, 2002 11:11 AM
 To: NIPP, SCOTT V (SBCSI); 'Ryan Jameson (USA)'; [EMAIL PROTECTED]
 Subject: Re: [PHP-DB] HTML Forms question...
 
 
  OK.  If I am using the POST method and the checkbox 'name' for all
  of the checkboxes is 'system', how do I access the results?  I am
  researching on the PHP site trying to figure out what this 
 array is, and
 how
  I access this if the index name is the same for all 
 elements.  I am hoping
  that this data will be in an array and I can simply loop through the
  contents of the array.  If this data is stored in a hash 
 (Perl word for
 this
  type of array, not sure if it's the same in PHP), how do I 
 access this
 data
  since the index for every element would be the same?
  I am SURE that I am probably missing some important conceptual
  issues here, but still learning as I go.  Unfortunately, 
 this probably
 means
  that I will be completely rewriting this application at 
 least once in the
  future.  Oh well, live and learn.  Thanks again for the help.
 
 If you have multiple checkboxes with the same 'name' then you 
 should name
 then with brackets, [], such as 'system[]'. This will tell 
 PHP to make the
 results an array when the form is submitted.
 
 For any of the 'submit[]' checkboxes that are checked, they 
 will be present
 in PHP array on the processing page. Those unchecked will not 
 be present.
 
 Say you have the following.
 
 input type=checkbox name=submit[] value=1One
 input type=checkbox name=submit[] value=2Two
 input type=checkbox name=submit[] value=3Three
 
 If the method on your form is POST, and the user checks One 
 and Three, then
 you'll have the following values in PHP on the ACTION page of 
 the FORM.
 
 $_POST['submit'][0] == 1
 $_POST['submit'][1] == 3
 
 From that data, though, there's no way to tell that checkbox 
 Two was not
 checked, unless you go through and check all of the values. 
 That's fine for
 small forms, but a hassle for large ones.
 
 You could also name your checkboxes like this:
 
 input type=checkbox name=submit[1] value=1One
 input type=checkbox name=submit[2] value=2Two
 input type=checkbox name=submit[3] value=3Three
 
 and if the user checks one and three again, you'll get
 
 $_POST['submit'][1] == 1
 $_POST['submit'][3] == 3
 
 Hopefully that clears some things up. If you have any other 
 questions, just
 ask.
 
 ---John Holmes...
 
 -- 
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php