|
||||
Sending Web Forms via EmailThere are a number of ways to process electronic forms via the World Wide Web. YorkInfo information providers can now process forms using a mail re-direction script called FORMMAIL. Before attempting to process forms with FORMMAIL, you should be familiar with the basic concepts of WWW forms and their HTML tags. All WWW Forms have METHOD and ACTION attributes. In this case, the method will be to "POST" the form's fields; the "ACTION" will be a URL which runs the FORMMAIL script. Thus your form should have the following structure: <FORM METHOD="POST" ACTION="http://www.yorku.ca/cgi-bin/formmail.pl"> ... HTML text, input and other form tags, including a submit button </FORM> In order to specify the subject line, recipient, etc, FORMMAIL supports a number of special input fields. These fields are explained below: recipientThis is who the form's contents will be sent to after they have been decoded, etc... The best idea is to have a hidden input somewhere in your form: <input type=hidden name="recipient" value="youremail@your.host"> This field is necessary if you want your form contents to be sent anywhere. Without this field the form will not work. The rest of these are actually optional, but it will be beneficial if you use them. subjectThis will relay the subject of your form to the script. You should also use a hidden type for this: <input type=hidden name="subject" value="Your Subject"> The subject field will then appear as the subject in your mail. You can allow them to type in the subject simply by taking out the value"" section and changing the type to text in the above example. This is the remote users' email address. Helpful if you want to be able to reply. Use a regular text input for this one. <input type=text name="email"> This allows the user to input his/her own email address. realnameThis one tells you the remote users realname. Nice to have added to your email message. Use a regular text field for this one also: <input type=text name="realname"> This allows the user to input his/her own name. redirectThis variable should only be used if you want to redirect the user to a different url when they are done completing the form. The type should be hidden and the url should be placed in the value="" attribute. <input type=hidden name="redirect" value="http://your.address/to/file.html"> This gets rid of the user having to see that ugly file telling them what they submitted. requiredIf you wish that certain fields in your form to be filled in before the user can successfully submit the form. For example say that you have a form, and you want the user to provide their name and phone number in order to be able to submit the form, you would use a syntax such as: <input type=hidden name="required" value="name,phone"> If the required fields are not filled in, the user will be notified of what they need to fill in, and a link back to the form they just submitted will be provided. missing_fields_redirectThis field allows you to specify a URL that users will be redirected to if there are fields listed in the required form field that are not filled in. This is so you can customize an error page instead of displaying the default. <input type=hidden name="missing_fields_redirect" value="http://your.host.com/error.html"> sortThis field allows you to choose the order in which you wish for your variables to appear in the e-mail that FormMail generates. You can choose to have the field sorted alphabetically or specify a set order in which you want the fields to appear in your mail message. To sort alphabetically: <input type=hidden name="sort" value="alphabetic"> To sort by a set field order: <input type=hidden name="sort" value="order:name1,name2,etc..."> env_reportAllows you to have Environment variables included in the e-mail message you receive after a user has filled out your form. Useful if you wish to know what browser they were using, what domain they were coming from or any other attributes associated with environment variables. The following is a short list of valid environment variables that might be useful: REMOTE_HOST - Sends the hostname making the request. REMOTE_ADDR - Sends the IP address of the remote host making the request. REMOTE_USER - If server supports authentication and script is protected, this is the username they have authenticated as. *This is not usually set.* HTTP_USER_AGENT - The browser the client is using to send the request. There are others, but these are a few of the most useful. For more information on environment variables, see: The CGI Resource Index: Documentation: Environment Variables For example if you wanted to find the remote host and browser sending the request, you would put the following into your form: <input type=hidden name="env_report" value="REMOTE_HOST,HTTP_USER_AGENT"> print_configThis field allows you to specify which of the config variables you would like to have printed in your e-mail message. By default, no config fields are printed to your e-mail. This is because the important form fields, like email, subject, etc. are included in the header of the message. However some users have asked for this option so they can have these fields printed in the body of the message. The config fields that you wish to have printed should be in the value attribute of your input tag separated by commas. If you want to print the email and subject fields in the body of your message, you would place the following form tag: <input type=hidden name="print_config" value="email,subject"> print_blank_fieldsprint_blank_fields allows you to request that all form fields are printed in the return HTML, regardless of whether or not they were filled in. FormMail defaults to turning this off, so that unused form fields aren't e-mailed. If you want to print all blank fields: <input type=hidden name="print_blank_fields" value="1"> From here you can have any other fields in your form that you wish. They may be comprised of any combination of the html form elements and there is no limit to how many you may out in a form, except those imposed on you by your server software. Please note that the above fields are a small sub-set of those suported by the FormMail script. If you wish to know about other fields supported see the link below. For complete information on FormMail and other CGI scripts, see Matt Wright's Script Archive. |