From icon-group-sender Sat Feb 4 19:41:11 1995 Received: by cheltenham.cs.arizona.edu; Sat, 4 Feb 1995 19:40:58 MST Date: Sat, 4 Feb 95 20:43:44 CST From: goer@mithra-orinst.uchicago.edu (Richard L. Goerwitz) Message-Id: <9502050243.AA08637@mithra-orinst.uchicago.edu> To: icon-group@cs.arizona.edu Subject: more Icon, CGI Errors-To: icon-group-errors@cs.arizona.edu Status: R Another invitation to Icon users interested in the Web and CGI scripts.... Not all clients implement mailto, so if you want, say, for people reading an article you wrote to be able to mail you comments from a form, you need a form and a CGI script to do this. Here are ex- amples of both. Appended below, immediately after my signature, is a short HTML form. After that is an Icon program that does the mailing. It is simple, and probably could be improved in many ways. I provide it here merely as an example. Naturally, the mailing addresses and hard-coded system files will need to be changed. Name the form anything you want. Compile the Icon program and put it into the cgi-bin directory. I recall when I first installed the executable running into problems with version 8 of Icon. Version 9, though, worked fine. Anyone wanting to take a look at how the form works can just jump to the end of one of the following documents. I tend to put an HREF to the comments form at the end of docs I place online. http://oi.uchicago.edu:1080/pub/stuff/accents/accents.html http://oi.uchicago.edu:1080/pub/papers/goerwitz/sbl94talk/sbl94talk.html Richard Goerwitz =============================== cut here ========================= Feedback Form

Feedback Form

This form offers a quick, easy way of forwarding comments back to me. Just fill out the fields below, and then click on the "mail comments" button near the end.

E-mail: Your name:

Paper title:

Comments you would like to offer:

If you prefer, send your comments to me manually, using your local system mailer


Richard L. Goerwitz, goer@midway.uchicago.edu
================================ cut here ========================== ############################################################################ # # File: forward_comments.icn # # Subject: Program to forward comments sent via a fillout form # # Author: Richard L. Goerwitz # # $Revision$ # ############################################################################ $define MYADDRESS "goer@midway.uchicago.edu" procedure main(a) local i, cl, n, name_tbl, f, sender, comments, nam, subj cl := integer(getenv("CONTENT_LENGTH")) name_tbl := table() # # output a minimal header, terminated by two newlines # write("Content-type: text/html\x0A\x0A") # # check that the request is correctly formatted; output # error message if it's not # getenv("REQUEST_METHOD") == "POST" | { writes("

error: METHOD must = \"POST\"

") exit(1) } getenv("CONTENT_TYPE") == "application/x-www-form-urlencoded" | { writes("

error: this script is for decoding form results only

") exit(1) } # # enter name=value lines as key/value pairs in name_tbl # while line := makeline(&input, "&", cl) do { line := unescape_url(map(line, "+", " ")) line ? { n := tab(find("=")) move(1) if not (/name_tbl[n] := tab(0)) then { writes("

error: duplicate field name, ", n, "

") exit(1) } } } writes("Feedback Submission Results") writes("") writes("

Feedback submission results:

") # # Collect the mailing address of the sender & his or her comments # sender := ("" ~== \name_tbl["sender"]) | { writes("

error: you forgot to give your e-mail address

") exit(2) } comments := ("" ~== \name_tbl["comments"]) | { writes("

error: no comments found!

") exit(2) } nam := ("" ~== \name_tbl["name"]) | "(unknown)" title := ("" ~== \name_tbl["title"]) | "(unspecified)" subj := "comments from " || nam || " (" || sender || ") regarding " || title # # Send off comments using system mailer # f := open("Mail -s '"|| subj ||"' "|| MYADDRESS, "pw") | { writes("

error: mailer offline

") exit(3) } write(f, comments) close(f) # # Report results to the comment-er # writes("

Your comments have been successfully forwarded.

") writes("

Here is the text of what you sent:

") writes("
", comments, "

") writes("

Thanks for your input,

") writes("

Richard Goerwitz

" || MYADDRESS || "

") writes("") exit(0) end # # concatenate series of non-ampersands into lines; stop # when you have read the number of characters in cl (arg # 3); stop_c is going to be "&" # procedure makeline(f, stop_c, cl) local line, c static c_count initial c_count := 0 line := "" while c := reads(f) do { if (c_count +:= 1) > cl then break if c == stop_c then break line ||:= c } return "" ~== line end # # turn &xx (where xx are hex digits) into an integer; # output the character with that internal integer value # procedure unescape_url(url) local new_url new_url := "" url ? { while new_url ||:= tab(find("%")) & move(1) do new_url ||:= char(hex(move(2))) | tab(0) new_url ||:= tab(0) } return new_url end # # Bob Alexander's hex->integer code (overkill here) # procedure hex(s) local a,c a := 0 every c := !map(s) do a := ior(find(c,"0123456789abcdef") - 1, ishift(a,4)) | fail return a end # # procedure hexstring(i,n,lowercase) local s, hexchars, sign i := integer(i) | runerr(101, i) sign := "" if i = 0 then s := "0" else { if /n & i < 0 then { sign := "-" i := -i } hexchars := if \lowercase then "0123456789abcdef" else "0123456789ABCDEF" s := "" until i = (0 | -1) do { s := hexchars[iand(i,15) + 1] || s i := ishift(i,-4) } } if \n > *s then s := right(s,n,if i >= 0 then "0" else hexchars[16]) return sign || s end