logo       Dave's Online Memory
doform - cgi script to save form submission to data file You: 38.103.63.58 Friday Dec 5, 2008 12:36AM PST
Features Usage Download Copyright

Features

  1. Relies on Lincoln Stein's venerable CGI.pm module. Available on CPAN.
  2. Restricts use to list of servers spelled out in script
  3. No html is output in any event. on success or failure,
  4. Redirects to pages specified in form fields.
  5. Data is saved in comma-delim'd format, single record to a line
  6. Path to data file is derived from prefix (/usr/local/data, for instance), plus web server host name. this allows for use on multiple sites.
  7. Data file must already exist. must be writable by web server. for 'normal' apache installation, should be owned by user, nobody, or on redhat linux, user apache. suggest special group of users to retrieve data (perhaps www?). permissions would then be 660 for apache.www or for nobody.www
  8. Email notification is sent to the webmaster of the server that hosts the script. The sender is web-robot at the same server.
    The email lists the URL of the form that was submitted, the name of the data file to check, and success or failure status of the script.
  9. Data file name allows only upper, lower case, numbers and underscore.
  10. Required fields:
    • redirect - fully-qualified url of destination on success
    • error - fully-qualified url of destination on failure
    • fields - list of fields to save. order will be retained.
    • file - name of file to save results into. must already exist. name only, no path info.

Usage

  1. Create a form containing the required fields: fields, redirect, error, file.
  2. Insert a hidden field in the form that lists all the fields that you wish saved to the data file. For instance, let's assume that a form contains the fields: name, address, city, state, country, phone. The hidden field would look like this:
    <input type="hidden" name="fields" value="name,address,city,state,country,phone">
    Note the lack of any spaces.
  3. Create the data file in the data directory. Assuming a base directory name of /usr/local/data, and a server name of grox.net, the data directory name would be: /usr/local/data/grox.net. This directory must already exist, be readable and writable by the web server daemon, and off-limits to otherrs. This is to ensure the privacy and the integrity of the data.
    Assuming a data file name of mydata, the field in the form would look like: <input type="hidden" name="file" value="mydata">
    Note that the file name does not include any path information. Assuming the conditions above, the full path that the script would update would be: /usr/local/data/grox.net/mydata
    If the web server is running as user apache, and a group named 'www' exists to update web pages, these commands would create the empty data file:
    cd /usr/local/data/grox.net
    touch mydata
    chown apache.www mydata
    chmod 660 mydata
  4. Create an html page to notify the user of success. Update the original form with the hidden field, redirect. This must be a full URL since this is where the client's browser will be redirected. The tag would look like:
    <input type="hidden" name="redirect" value="/some/full/url.html">
  5. Create another html page to notify the user of an error. The same precautions apply; it must be a full URL. The form must contain a hidden field named, error that contains this URL. This tag would be:
    <input type="hidden" name="error" value="/some/full/errorurl.html">

Download

Shift-click to download the script here.

Copyright

Copyright (c) 2002, Dave W. Capella All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of Dave Capella nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

...dave


silly cat image Top of Page FEEDBACK      Comments, Corrections & Questions welcome