Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

CGI Form / Email

 [1/4] from: mechtn::charter::net at: 31-Mar-2002 11:58


Hi, I am working on a cgi form/email program to create a support request form for my company.. So far its going pretty well except i cant figure out how to break the fields apart even more than just from/subject/message... i want them to fill out multiple fields and it list it all in the message... currently my code looks like.. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #!rebol -cs REBOL [ Title: "Sends Support Request via CGI Form" Date: 29-March-2002 File: %cgiemailer.r Purpose: { Uses a Web form to send an support request (email) message. } Category: [cgi email markup net 3] ] supportmail: [support--nex-tekinc--com] system/user/email: [support--nex-tekinc--com] system/schemes/default/host: "mail.nex-tekinc.com" print "Content-Type: text/html^/" ;-- Required Page Header print "<html><body><h2>Results:</h2>" cgi: make system/standard/email decode-cgi system/options/cgi/query-string either all [ email? try [cgi/email: load cgi/email] ][ print [<B> "Sending Support Request Now"</B><br>] send/header [ksmith--nex-tekinc--com] cgi/content cgi ][ print "<B>Invalid email to or from address</B>" ] print [ "Customer Number:" <B> cgi/custnum </B><P> "Email:" <B> cgi/email </B><P> "Name:" <B> cgi/name </B><P> "Problem:" <B> cgi/content </B><P> ] print "</body><html>" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I have the following fields in the webpage.. custnum email name content My goal is to have the customer number appear in the subject, and any other information like name and problem appear in the message body.. I may have more than just these two fields once its all said and done.. Thanks to anyone who can help me out.. Koie Smith [ksmith--nex-tekinc--com]

 [2/4] from: cybarite:sympatico:ca at: 31-Mar-2002 11:13


Hi Koie, If you are trying to have the request form posted and handled by a REBOL script invoked by CGI, I don't follow why you want the email send. Your CGI script will have all of the data that was posted to your web address. You can simply write them to a journal file to process later with write/append If you want to send a reply to the person who raised the request, you would not normally use email to accomplish that but just send that back on the reply to the post. If you want to send an alert to another user to tell them something's been logged, then you might just send the URL to retrieve the data from the journal file. e.g. send [customer--service--my-company--com] {New Item A new entry has been added to the journal for your action. See http://my-company.com/cgi-bin/get-item.r?key=123456789 } Then you need to add script get-item.r to do the lookup and supply the information that is needed. The basics that you have with the decode-cgi make this a very easy task. or at least that is what I would do ... rather than email. ----- Original Message ----- From: "mechtn" <[mechtn--charter--net]> To: <[rebol-list--rebol--com]> Sent: Sunday, March 31, 2002 12:58 PM Subject: [REBOL] CGI Form / Email
> Hi, I am working on a cgi form/email program to create a support request
form for my company..
> So far its going pretty well except i cant figure out how to break the
fields apart even more than just from/subject/message... i want them to fill out multiple fields and it list it all in the message...
> currently my code looks like.. > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<<quoted lines omitted: 36>>
> content > My goal is to have the customer number appear in the subject, and any
other information like name and problem appear in the message body.. I may have more than just these two fields once its all said and done..

 [3/4] from: tomc:darkwing:uoregon at: 31-Mar-2002 12:56


last year I was asked to modify an existing cgiemail to work a bit differently... Instead I wrote a a workalike replacement (it was quicker) -- I still don't think anyone knows. I here is a cleaned up version of what I am using I hope I did not introduce any tyops. #! /private/bin/rebol -csq rebol[ Author: "Tom Conlin" Date: 2001-Jul-19 File: %cgiemail.cgi purpose: { drop-in replacement for MIT's standard cgiemail with a couple of tweaks. First does not use sendmail which was improperly translating email addressed from a vitual hostname to the machine name when it was not asked to. (caused problems in out particular case) Second I am also saving a log of each transaction to a file. (because I was told to) the basic idea is that with this program you can validate and email arbitary forms by writing your forms using certain conventions and having a text template of the email you would like to be sent to various people when the form is submitted. their doc: http://web.mit.edu/wwwdev/cgiemail/ their source ~100k <snicker>: http://www.mit.edu/afs/net.mit.edu/reference/source/web-cgi/ } ] ;;; see: hhtp://www.rebol.com for free "rebol/core" interperter print "Content-Type: text/html^/" ;;; Edit these to suit your enviroment accept-domain: <domain-your-form-is-on> ;otherwise you may end up a spammer maintainer-email: <your-email-adress> set-net [maintainer-email <mailhost.your.domain> none none none] ; only used if you are writing out a log lock-file: %/path-to-your-lockfile output-file: %/path-to-your-logfile ;;; TO-DO read a local config file that contains domains to accept ;;; template files from ;;; url-decode and parse the string into a block of name-value pairs cgi: copy "" either system/options/cgi/request-method = "POST"[ ;;; read the block of name = value pairs ;;; see how long the string we need to read is len: load system/options/cgi/content-length ;;; make an empty string that is long enough ;;; read the string from stdin buffer: make string! (:len + 8) while [not zero? read-io system/ports/input buffer :len] [append cgi buffer clear buffer] ] [ either system/options/cgi/request-method = "GET" [cgi: copy system/options/cgi/query-string] [print "implement command line testing already"] ] cgi: decode-cgi cgi keyval: copy [] foreach x cgi [append/only keyval to-string :x ] ;;; check-that the template is from somwhere we have agreed to read from ;;; this really needs to be done some better way if not find (select keyval "template") accept-domain[ print "we are coming to get you now" q ] template: read to-url (select keyval "template") placeholders: copy [] ;alfa: charset {#"A"=#"Z" #"a"-#"z"} mark: copy "" parse template [ any [ (mark: copy "") to "[" copy mark thru "]" (append placeholders mark) ] to end ] sort/compare placeholders func[a b][(length? a ) > (length? b )] ;;; replace the place holders in the template with the values from the cgi foreach [k v] keyval [ k: rejoin[ "[" :k "]" ] if all[ (equal? v "") (equal? copy/part k 10 [required_ ) ][ v: rejoin[ {<font color="red">**} :k {</font>} ] ] replace/all template k v ] ;;; balk if a required field is missing if find template {<font color="red">**[required_}[ template: copy next find template "^/^/" print {<html> <head> <title>Failed</title> </head> <body> <h1> Required fields missing</h1> <b>Please go back and fill in all required fields</b><p> } print replace/all template "^/" "<br>^/" print "</body></html>" quit ] ;;; remove leftover place holders ;;; such as those attached to unchecked checkboxes foreach ph placeholders[ replace/all template ph ""] ;;; strip the header info out of the template ;;; build a block of addressed to send to addy: copy/part next find template ":" find template "^/" template: copy next find template "^/" frm: load copy/part next find template ":" find template "^/" template: copy next find template "^/" sbj: copy/part next find template ":" find template "^/" template: copy next find template "^/" ;;; clean off the top of the template while [(pick template 1) = "^/" ][remove template] foreach ad parse addy "," [ ;;; build a mail header header: make system/standard/email [ To: ad From: frm Subject: sbj ] send/header to-email ad template header ] ;;; append a copy of the email to a logfile ;;; make sure only one cgi writes to the file at a time while [not error? try[read lock-file]][wait 2] write lock-file "" write/append output-file rejoin ["# "now/date "--" now/time "^/"] write/append output-file template delete lock-file ;;; output the happy ending version print read to-url (select keyval "success")

 [4/4] from: mechtn:charter at: 31-Mar-2002 16:24


I'm a consultant with a limited amount of clients because i only work with law firms, and meet their specalized needs. The purpose of this is to create a support request. Basically it emails the 4 people on my team whatever i decide to have the form fields contain. Name, Customer Number, Email, Problem, Date, etc... This way its an extra form of communication they can have for contacting us, and we want to log all our calls this way. I was setting up a MySQL database that was going to have a counter for each customer number based on what they entered later on down the road, but i'm not that far advanced in programming yet. Instead of just having a subject field and message body field, i want to break them down into more specific fields and say, Customer Number and Date show up in the title, and then the rest of the stuff in the message body. The software we uses allows us to attach emails and log all our phone conversations to each client... This is just an extra way to help keep records with problems, and also if it sends this email to all 4 people on my team, one of us may be able to address it faster than another.. We work as a close team and this is how we decided our goals would be accomplished... I dont have very much experiance, and i'm learning rebol as i go, so please be patient with me.. Thanks Koie Smith [ksmith--nex-tekinc--com]

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted