From: Jonathan S. <jn...@ge...> - 2004-08-09 11:39:44
|
On Fri, 2004-08-06 at 18:23, webmaster wrote: > I'm testing TFmail.pl, and have got it to work when I use a contact > form. The message is sent, the success page is presented to the client. > But I'm trying to account for all posibilities. Suppose someone > bookmarks the page to remind themselves of their message, and tries to > return to it in a later browser session? Here's the error that comes up: > > > Application Error > > An error has occurred in the program > > request method must be "POST" at /home/julie/bonfete/cgi-bin/TFmail.pl > line 116. > > > Has anyone come up with a more graceful way to handle this problem? I > suppose I could configure Apache to diallow any method but post on the > script, but that just replaces one error message for another. To be honest there is one school of thought that suggests that we are being too nice as it is - that the program should simply give the appropriate status code for "Request method not allowed" and let the server decide what to do. However I have considered that it might be useful to actually be able to specify a template that can be used for a GET request - this could simply be the form itself or something else. The problem with these things is that it seems that none of the developers have much time for anything other than urgent bug-fixes at the moment - I have copied the developers list in case there is anyone with spare time. /J\ |
From: Jonathan S. <jn...@ge...> - 2004-08-09 16:36:14
|
On Mon, 2004-08-09 at 17:17, webmaster wrote: > webmaster wrote: > > >>> Application Error > >>> > >>> An error has occurred in the program > >>> request method must be "POST" > > > I think sending "405 method not allowed" is the best course > > of action. > > > I've come with a bit of a hack to generate the correct response, > and thought I'd share it with the list. This hack requires Apache, > mod_rewrite, and PHP. There are 2 steps: > > 1. conditionally rewrite the url to the TFmail script if request method > is not post. I'll assume that TFmail is located in /cgi-bin/ > > RewriteEngine on > RewriteBase / > RewriteCond %{REQUEST_METHOD} !POST > RewriteRule ^cgi-bin/TFmail.pl$ /error405.php [L] > > > 2. create error405.php, and add the following at the top, *before* > any html is sent out > > <?php > header("Content-Type: text/html; charset=ISO-8859-1", "true", "405"); > ?> > > Set the charset to whatever you use. The second argument ensures > that PHP replaces any content-type header it might have sent out. > The "405" tells PHP to send that code as the http response code. > It could be done by changing the single line: die 'request method must be "POST"'; to: print $treq->cgi()->header(-status => 405); exit; and creating the appropriate 405 error page if required. > > > If TFmail users would prefer that a GET request simply return the user > to the contact form page, you can modify step (1) above and skip step > (2). Thus, this solution requires only Apache and mod_rewrite. Let's > assume that the form is located at /contactform.html > > > RewriteEngine on > RewriteBase / > RewriteCond %{REQUEST_METHOD} !POST > RewriteRule ^cgi-bin/TFmail.pl$ /contactform.html [R,L] > > > Users may want to send a permanent redirect in such cases. Consult the > Apache manual for details on how to fine tune this. I think that in this case it would be better to be have a redirect configured in the .trc file - or indeed have TFmail.pl actually have another potential template that could be filled out from the GET request query string - that way it would be possible for people to create links to a form with some of the fields filled in or with a different config or other things that I can't think of at the moment. Anyway thanks for your input /J\ |
From: Jonathan S. <jn...@ge...> - 2004-08-10 09:11:05
|
On Tue, 2004-08-10 at 06:39, webmaster wrote: > Jonathan Stowe wrote: > > > On Mon, 2004-08-09 at 17:17, webmaster wrote: > > > >> webmaster wrote: > >> > >> 1. conditionally rewrite the url to the TFmail script if request > >> method is not post. > >> > >> 2. create error405.php > > > > It could be done by changing the single line: > > > > die 'request method must be "POST"'; > > > > to: > > > > print $treq->cgi()->header(-status => 405); > > exit; > > Thanks for the tip. I tried to implement it, but the results were a > little strange. The response from the server after the change was > "HTTP/1.1 405 OK". Only the numeric code has changed; the text message > is the same. That's a bit confusing, I think. > Yes, it is server dependent on what the string is - changing the numeric 405 to the quoted string '405 Request Method Not Allowed' will do the trick. > I also tested it by changing the code in the script to 403, and got > similar results: "HTTP/1.1 403 OK". > > > and creating the appropriate 405 error page if required. > > I've configured Apache to use 405.php as my error page for 405 errors, > but it is not used when I access TFmail with GET. > > > it would be better to be have a redirect configured in the .trc file > > - or indeed have TFmail.pl actually have another potential template > > that could be filled out from the GET request query string - that way > > it would be possible for people to create links to a form with some > > of the fields filled in or with a different config or other things > > that I can't think of at the moment. > > Those could indeed be very useful. > Well the latest development version of TFmail.pl in the CVS now has this functionality, we are aiming to make a release sometime this week. If you have access to CVS then you can get it using the instructions here: http://sourceforge.net/cvs/?group_id=39625 for some reason the "browse cvs repository" function isn't up to date. > > Anyway thanks for your input > > Sure. I hope I didn't just add more noise. |
From: Jonathan S. <jn...@ge...> - 2004-08-11 14:45:02
|
On Tue, 2004-08-10 at 06:39, webmaster wrote: (I wrote): > > > it would be better to be have a redirect configured in the .trc file > > - or indeed have TFmail.pl actually have another potential template > > that could be filled out from the GET request query string - that way > > it would be possible for people to create links to a form with some > > of the fields filled in or with a different config or other things > > that I can't think of at the moment. > > Those could indeed be very useful. The latest version of TFmail has just been uploaded to http://nms-cgi.sf.net/scripts.shtml it includes the option to return a 405 status on a GET request, redirect to another page or display a template. This is all documented in the README. /J\ |
From: Jonathan S. <jn...@ge...> - 2004-08-11 14:45:02
|
On Tue, 2004-08-10 at 06:39, webmaster wrote: (I wrote): > > > it would be better to be have a redirect configured in the .trc file > > - or indeed have TFmail.pl actually have another potential template > > that could be filled out from the GET request query string - that way > > it would be possible for people to create links to a form with some > > of the fields filled in or with a different config or other things > > that I can't think of at the moment. > > Those could indeed be very useful. The latest version of TFmail has just been uploaded to http://nms-cgi.sf.net/scripts.shtml it includes the option to return a 405 status on a GET request, redirect to another page or display a template. This is all documented in the README. /J\ |