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

[REBOL] Re: Newbie Rebol (CGI) questions

From: Gary::Jones::usap::gov at: 17-Apr-2004 7:28

Hi, Kai, From: Kai Peters KP> From the web tutorials I have doctored the script below KP> together which leaves me with three questions: KP> 1) Why do I receive an error if i omit the print line KP> immediately after the REBOL [] header? The web HTTP protocol requires that the web server return a designation for the type of content that is to be sent, and that this designation shall be followed by a blank line before any content is actually sent. The CGI script may be designed to handle form input, but in a way of speaking, its "responsibility" is to return something to the browser. Hence the "Content-type: text/html" which is the usual html web type. As an aside, notice that this line ends with a escaped newline character "^/". The print command supplies one newline and a second must be supplied inorder for there the be a "blank line" following this line. KP> 2) How can I insert LFs in the line KP> " emit [ mold var mold value ]" KP> to make the mail more readable? This "emit" function is one of the language designer's favorite methods for forming large strings from static text, variables, etc. However, I suspect it may be causing confusion for you where the answer might otherwise be obvious. Using a more linear method makes it more obvious how to manage the formatting of strings: ;create a decent size string in order to save ; time having to "grow" it later response: make string! 2000 ; skip code for brevity ;... foreach [var value] decode-cgi read-cgi [ append response var append response "=" append response value append response newline ] which can be shortened to: response: make string! 2000 ;... foreach [var value] decode-cgi read-cgi [ append response reduce [var "=" value newline] ] Since the variables are in a block, REBOL needs to know to substitute their values, which is the purpose of the 'reduce command. This can be further shortened to: response: make string! 2000 ;... foreach [var value] decode-cgi read-cgi [ repend response [var "=" value newline] ] in which the "reduction" occurs within the repend command. At this juncture, you will more readily recognize the emit function. KP> 3) How can i do the set-net stuff permanently? Place a user.r file with the requisite 'set-net command in the executable directory. This essentially just reads the same exact command in before presenting REBOL's command line. By the way, before sending your email through the CGI interface, you may wish to add two things. First add a first line that will then become the subject for the email message, like: response: rejoin ["[ form] sent: " now newline response] This makes it easy to spot mail that comes from your website form system. Second, send the user some feedback that the information was taken and that they can expect a response back, like: .... header: make system/standard/email [ To: [[kpeters--somedom--net]] From: [[kpeters--somedom--com]] Subject: "Message with a header" Organization: "Super Org" ] either error? [send/header [kpeters--somedom--net] response header][ web-response: {There has been an error in processing your information. While the error has been logged, you may wish to resubmit this information if you have not heard back within 48 hours.} write/append %/path/to/web/error/log/log.txt response ][ web-response: {Thank you for submitting this information. Your response will be processed, and you should receive an answer within 48 hours.} ] print web-response Hope this helps demystify the REBOL way of managing CGI form data. --Scott Jones