[Web4lib] CGI Forms: checkboxes and stringing of multiple fields
Cloutman, David
DCloutman at co.marin.ca.us
Mon Dec 10 18:22:29 EST 2007
PHP functions in a similar fashion. Grouped check boxes are passed as an
array.
<form action="foo.php" method="post">
<input type="checkbox" name="bar[]" value="one" /> One<br />
<input type="checkbox" name="bar[]" value="two" /> Two<br />
<input type="checkbox" name="bar[]" value="three" /> Three<br />
<input type="checkbox" name="bar[]" value="four" /> Four<br />
<input type="checkbox" name="bar[]" value="five" /> Five<br />
<br />
<input type="submit" value="Check checks" />
</form>
This foo.php would show you the values in the array, if any boxes were
submitted. If none were submitted, is would not be set.
<html>
<body>
<?php
if (isset($_POST['bar'])) {
?>
<pre>
<?php
print_r($_POST['bar']);
?>
</pre>
<?php
}
else {
echo "No boxes were checked.";
}
?>
</body>
</html>
A similar technique for PERL is described here:
http://www.cgi101.com/book/ch5/text.html
Basically giving the same name to a group of checkboxes will cause them
to be processed as an array, though is seems for PERL, the brackets are
not used.
Basically, if a checkbox is not checked, it is not passed to the script.
Therefore, you must test for the existence of that variable. My gues is
that your code needs to use the exists() function, which is the
equivalent of PHP's isset(), so perhaps it needs to look like this:
if (exists($FORM{ckeckbox}) && $FORM{ckeckbox} eq "yes") {
print MESSAGE "I checked the library catalog before
submitting.\n";
}
else {
print MESSAGE "I did not check the library catalog before
submitting.\n";
}
- David
---
David Cloutman <dcloutman at co.marin.ca.us>
Electronic Services Librarian
Marin County Free Library
-----Original Message-----
From: Cloutman, David
Sent: Monday, December 10, 2007 1:42 PM
To: 'Poulter, Dale'; Baker, Tammy K; web4lib at webjunction.org
Subject: RE: [Web4lib] CGI Forms: checkboxes and stringing of multiple
fields
She would also need a web server installation, mailer, and correct CPAN
libraries, and would have to make the environment similar enough to her
production server that it was a realistic test of the script. I'm not so
certain that this is an ideal way to approach creating a development
environent.
- David
---
David Cloutman <dcloutman at co.marin.ca.us>
Electronic Services Librarian
Marin County Free Library
-----Original Message-----
From: web4lib-bounces at webjunction.org
[mailto:web4lib-bounces at webjunction.org] On Behalf Of Poulter, Dale
Sent: Monday, December 10, 2007 1:28 PM
To: Baker, Tammy K; web4lib at webjunction.org
Subject: RE: [Web4lib] CGI Forms: checkboxes and stringing of multiple
fields
You could install perl on your pc for testing.
--Dale
---------------------------------------
Dale Poulter
Automation Coordinator
Library Information Technology Services
Vanderbilt University
Suite 700
110 21st Avenue South
Nashville, TN 37240
(615)343-5388
(615)343-8834 (fax)
(615)207-9705 (cell)
dale.poulter at vanderbilt.edu
-----Original Message-----
From: web4lib-bounces at webjunction.org
[mailto:web4lib-bounces at webjunction.org] On Behalf Of Baker, Tammy K
Sent: Monday, December 10, 2007 1:20 PM
To: web4lib at webjunction.org
Subject: RE: [Web4lib] CGI Forms: checkboxes and stringing of multiple
fields
I'm using perl (but I'm certainly not an expert in it). Also, I don't
have the webform or the script on the web server yet but was wondering
if there's anyway to test their functionality on a PC (if I have .htm
files on my C:\ drive, I can open them with browsers to get a preview of
how they look but I'd like to know if there's something similar to test
cgi scripts).
Thank you again,
Tammy K. Baker
-----Original Message-----
From: Cloutman, David [mailto:DCloutman at co.marin.ca.us]
Sent: Monday, December 10, 2007 1:08 PM
To: Baker, Tammy K; web4lib at webjunction.org
Subject: RE: [Web4lib] CGI Forms: checkboxes and stringing of multiple
fields
Can you tell us which particular email script / scripting language you
are working with? We will need to know that to answer your question.
---
David Cloutman <dcloutman at co.marin.ca.us> Electronic Services Librarian
Marin County Free Library
-----Original Message-----
From: web4lib-bounces at webjunction.org
[mailto:web4lib-bounces at webjunction.org] On Behalf Of Baker, Tammy K
Sent: Monday, December 10, 2007 10:37 AM
To: web4lib at webjunction.org
Subject: [Web4lib] CGI Forms: checkboxes and stringing of multiple
fields
Greetings everyone,
I'm working on interlibrary loan request forms and I'm seeking some
insight since I'm really rusty and not much of a programmer. First, it
was decided that phone numbers would be in separate fields rather than
one field; so we went from this:
Phone# <input name="Phone" type="text" size="13">
to this:
Phone# (
<input name="AreaCode" type="text" size="3">
)
<input name="Prefix" type="text" size="3">
-
<input name="Number" type="text" size="4">
The part of the cgi script pertaining to the phone number had
print MESSAGE "Phone#: $FORM{Phone}\n";
Now I have to string three fields together and wanted to know if the
following would work (to display something like 832-555-1212):
print MESSAGE "Phone#: $FORM{AreaCode}-$FORM{Prefix}-$FORM{Number}\n";
Second, I have never seen information on how checkboxes are treated with
cgi. For example, the following on the form:
Did you check the library catalog to determine whether the item is
available locally? <input type="checkbox" name="checkbox"
value="checkbox">
I'm not sure how to get the results of the checkbox from the webform to
the email recipient. I'm probably way off but would something like the
following work:
if ($FORM{ckeckbox} = "yes") {
print MESSAGE "I checked the library catalog before submitting.\n";
}
else {
print MESSAGE "I did not check the library catalog before
submitting.\n";
}
Thank you so much in advance for any insight.
Sincerely,
Tammy K. Baker, Technology Librarian
Automated Library Services
District Services and Training Center
North Harris Montgomery Community College District 5000 Research Forest
Drive The Woodlands, Texas 77381-4356 USA
Telephone: (832) 813-6652
Facsimile: (832) 813-6614
Electronic mail: tammy.k.baker at nhmccd.edu
<mailto:tammy.k.baker at nhmccd.edu>
NHMCCD is becoming
Lone Star College System
_______________________________________________
Web4lib mailing list
Web4lib at webjunction.org
http://lists.webjunction.org/web4lib/
Email Disclaimer: http://www.co.marin.ca.us/nav/misc/EmailDisclaimer.cfm
_______________________________________________
Web4lib mailing list
Web4lib at webjunction.org
http://lists.webjunction.org/web4lib/
_______________________________________________
Web4lib mailing list
Web4lib at webjunction.org
http://lists.webjunction.org/web4lib/
More information about the Web4lib
mailing list