CGI Problem: Array not properly read?
Sannyasin Sivakatirswami
katir at hindu.org
Mon Sep 2 01:49:00 EDT 2002
I recent found the CGI that I posted a few days ago has a problem where
a function that tests for missing fields from the form that was posted
is breaking.
The problem is: even though the fields are in fact filled in by the
client on the HTML form... the CGI is trapping at this point in the
script as if they were empty and then returning spurious data.
The script processes incoming POST data such that the name of the
field and the value are in an array called "tDataIn" where the keys
are the form input field names and the contents of each element is the
data entered into the form: At this point in the script I test for
missing fields, all of which should be filled in except the phone
number, extra address lines and the comments file which are allowed to
be empty. if any other fields are empty the script calls a function and
send the browser an HTML page with the list of fields the user left
empty.
Now, this script was working and now is occasionally breaking... I
can't figure it out. Sometimes the function is actually returning the
contents of other elements in the array....
=========
put keys(tDataIn) into tFields
## a line delimited list of all the input form field names.
sort lines of tFields
## now we build all of the input into a variable
repeat for each line x in tFields
put (x & tab & tDataIn[x] & cr ) after tSubmit
end repeat
## the above works... because I save tSubmit to a file (see below)
## and it looks fine
## Now check for missing fields
## This is the problematic part of the script that is generating
spurious
## results seemingly at random.
set the itemdel to tab
put empty into missing_fields
repeat for each line x in tSubmit
if (item 1 of x is not among the words of "09_Phone 13_add2
14_add3 19_comments" ) then
if item 2 of x is empty then put item 1 of x & "<br>" after
missing_fields
end if
end repeat
if missing_fields is not empty then
sendUserFeedback (missing_fields)
exit startup
end if
##########
## here is the function:
on sendUserFeedback missing_fields
put "Sorry, please fill in the following required fields, and submit
again. <BR>Do not click the BACK button in your browser. " into
tResponse
put "<BR><A HREF=" & quote &
"http://www.himalayanacademy.com/hawaii/iraivan/donate/" "e& ">
Please click this link instead to order again.</A>" & "<p>" after
tResponse
put missing_fields after tResponse
put "Content-Type: text/html" & cr
put "Content-Length:" && the length of tResponse & cr & cr
put tResponse
end sendUserFeedback
=========
The spurious results will be an HTML response like this:
================
Sorry, please fill in the following required fields, and submit again.
Do not click the BACK button in your browser. "
some text entered into the comments field
Katir at hindu.org
===========
Somehow in the above,where the variable "missing_fields" should be
empty the CGI is actually passing the content of some of the array
elements into the "missing_fields" variable, thereby triggering the
function, and passing the content of, in this case, the email and
comments elements. But, and this is really wierd... next attempt and it
will pass a different set of data to the same function... just the
first or last name for example....
Here is an example of the data in the variable tSubmit that the missing
fields handler is processing.. it looks perfect (tab separate the
name-value pairs)
00_item_name 2003 Iraivan Temple Calendar
01_Quantity 2
02_Subtotal US$32.00
03_Shipping US$0.00
04_Total US$32.00
05_cc# 123412341234
06_expmonth 01
07_expyear 02
08_email katir at hindu.org
09_Phone
10_First Siva
11_Last Katirswami
12_add1 107 Kaholalele RD
13_add2
14_add3
15_City Kapaa
16_State HI
17_Zip 96746
18_Country USA
19_comments test... .. forward this to me if you get it... Thanks
Any clues??
Hinduism Today
Sannyasin Sivakatirswami
Editor's Assistant/Production Manager
katir at hindu.org
www.HinduismToday.com, www.HimalayanAcademy.com,
www.Gurudeva.org, www.hindu.org
Read The Master Course Lesson of the Day at
http://www.gurudeva.org/lesson.shtml
More information about the metacard
mailing list