Version: v1.5.6
Content of this supply |
|
|---|---|
| ./formmailer/readme.htm | This readme - file |
| ./formmailer/first_sample | Directory, containing first sample to which the section "How to create a form" refers. |
| ./formmailer/basic_sample | Directory, containing sample for easy use. Just basic features are used here. |
| ./formmailer/advanced_sample | Directory, containing sample for advanced use. Advanced features are used here. |
| ./formmailer/upload_sample | Directory, containing sample for upload feature. |
| ./php-bin/ls | Directory, containing the Lexasoft php class framework. |
| ./php-bin/ls/config/mail.inc | General configuration file for sending email. Should be customized to fit to Your needs. |
| ./php-bin/ls/htmlmimemail | Directory, containing email framework by phpguru.org. Please check their website for details. |
|
Please note: Since Formmailer 1.5.1 there is no need to set "register_globals" to
"ON" when using PHP 4.2 or above. Formmailer 1.5.6 will be the last version to support both PHP4 and PHP5. We are going to withdraw PHP4 support in future. |
If You are updating from a previous version, please read update section.
| Please note: If You want to use upload function, please read the chapter about this module. |
Before You start updating, check the version of Your formmailer from the readme file in Your original supply.
For a list of changes see appendix g , please.
| Before You start, make a copy of Your current installation just to make sure... ;-). |
If You are updating from v.1.5.5:
If You are updating from v1.5.1_02, please do the following:
If You are updating from v1.5 or v1.5.1:
There are a few things to be kept in mind, using Lexasoft formmailer:
The easiest way to create and use a form with Lexasoft formmailer is to customize our samples. But, however, to create a form completely on Your own, You do have to do the following:
<?php
// Include formmailers library (make sure this points to the email.inc file from this delivery):
require_once "../../php-bin/ls/email.inc";
// Create Object and initialize from configurationfile.
$theFormMailer = new FormMailer();
$theFormMailer->initFromPropertyFile( "./formmailer.cfg");
// Output to Browser.
$theFormMailer->out();
?>
| Please note: The page You insert this code into, must be a page that will be parsed by php. Usually those files end with .php, .php4 or .php5. If You are not sure, please contact Your system administrator for assistance. |
There are only three things to be looked at:
Here is a very simple example of a form:
<form method="POST" action="%script%">
Your name: <input type="text"
name="name"
><br>
Your comment:
<textarea name="comment"></textarea><p>
<input type="submit"
value="send"
name="ok"
>
<input type="reset"
value="cancel"
name="cancel"
>
</form>
You can use Your favorite html editor to do that and therefore You can create the form with any design You like. You should save this template into the same directory as where Your form is to be found.
| Please note: Only the part between <body> and </body> of Your template will be used. |
Use the name of this file in Your configuration file in key "FormTemplate". (See point 3).
Fill in at least the following keys:
| FormTemplate: | The name of the template file for the form (see point 2) |
| MailRecipients: | The recipients of the feedback mail, seperated by ",". |
| MailSubject: | The subject of the feedback mail. |
We recommend to fill in the following keys as well, though this is not always neccessary:
| MailFrom: | Sender of the feedbackmail (Header "From:"). |
| MailReplyTo: | This adress will be written to Header 'ReplyTo'. This adress will be used, if the button "Reply" is pressed in the mailclient. |
| MailReturnPath: | Adress, to which the mail will be sent back, if it is undeliverably. |
| Please note: Write "%MailFrom%" for the last two keys.
Thus it is made sure, that they are identically to the value in
MailFrom:
MailFrom = myaccount@mydomain.com |
After finishing those steps, You do have a basic form, which sends You a simple list of posted fields per email. It might look like this:
Form was sent:
- name: Madonna
- comment: Nice site You\'ve got here !
- ok: send
Our first example shows, how this simple variant would look like.
In the following sections we will see how we can go on with this and we will have a closer look to the configuration file and the validation rules, provided with Lexasoft formmailer.
This first example, of course, is not very pretty at all. So how can we improve this result? There are several ways to do this:
The mail templates can be given in pure text and, in addition, in html format. For details please see the sample formmailer.cfg.
Since v1.5.5 Lexasoft formmailer directly supports upload of files to Your server. As this is a bit something special, we will handle it in this seperate chapter.
First of all: A fully working sample of the upload feature is included in this supply. We recommend to customize it to Your needs. Nevertheless it might be, You want to add upload capability to one of Your existing forms. So here is, how to do this.
<form method="POST" ENCTYPE="multipart/form-data" action="%script%">
<input type="hidden" name="MAX_FILE_SIZE" value="%UploadMaxFileSize%">
<input type="file" name="userfile">
Please note: Since this feature is new in v1.5.5, if You update from an earlier version, You must copy the upload lines from the formmailer.cfg and lang.XXX.cfg in formmailer/upload_sample to the corresponding files in Your installation. These lines are on the bottom of the files. There is no need to copy more than these lines, as no further changes are made. |
Please note: If You are unsure, which mime type to use, You can find out as follows:
|
| Please note: The file input field must not be optional. A file to upload in this upload form must always be given. |
| Please note: For a list of substitutes, used by upload feature, check Appendix F. |
Spam, unfortunately, is a serious problem, we must take care of. There two aspects about this:
Spammers do not only use "normal" mail to provide spam mails, but also forms as used in Lexasoft.de formmailers. They do this by posting unwanted content directly to the mailing script.
Spammers use special scripts, that can post to many thousands forms across the net in just a second. That's why You can't get them with any client side Javascript evaluation in Your form.
Use the Lexasoft.de server side evaluation insted to recognize spammers and prevent them from sending spam. Although there are (up to now) less special "anti spam features", the rate of recognizing spam in practice is nearly 100%. Some of the websites we operate, are confronted with several thousands spam attacks a day.
Most of them are unsuccessful, just one or two of them in a month may be successful and send a mail.
Here are some hints, how to do this.
One last hint: Always keep an eye on all mails, sent by Your formmailer. The feedback itself, of course, usually is sent to You, only. Lexasoft.de formmailer does not allow to send this mail to any other than the recepient, configured in formmailer.cfg.
But the response mail (if You provide one), usually is sent to the email adress, the user provides. Thus a spammer could send a mail to any email address abusing Your form. This is a danger, You must face.
First of all: consider, whether You really need a response mail. In some cases this is "counterproductive", as the user might feel disturbed from an automatic message.
If You need to provide a response mail, please keep an eye on the following:
This section shows You how to use configuration files. There are generally two configuration files used with Lexasoft formmailer: The formmailer.cfg (or similiar) which contains all configuration information and the language file, which can contain all messages. The language file is optional.
The configuration file syntax in fact is very simple. Here are the rules:
| Please note: The character point (".") in key in some cases is used for dividing purposes. |
| Please note: At the moment this works only once, not recursively. So MailReturnPath = %MailReplyTo% in our example will not work. |
These are the common rules for configuration files. Please also note some special rules for the Lexasoft Formmailer:
| Please note: This only works in that direction. It is not possible to use values from configuration file in language file. |
Thus You can create a configuration file, which does not contain any message in plain text, but only keys from language file. This way You can simply change language by changing the language file.
Our advanced sample shows You, how to do this.
MailReplyTo = %email%
Assumed, there is an input field, called "email" (value of name attribute in tag) and user filled in his email adress there, this makes sure, that the ReplyTo Header in mail will be users email adress. When You are watching the feedback mail in Your mail client and press the "Reply" button, users email adress will be automatically used.
To make sure, the
email adress is valid, please see appendix B -
validations.
Lexasoft formmailer provides some validation to check, whether users input was valid. These are the following:
A validation for a arbitrary field in configuration file generally is configured as follows:
<ValidationName>.<FieldName> = <ValidationParameter1>, [<ValidationParameter2>,...] <ErrorMessage>
For example a validation of minimum length could look like this:
ValMinLength.name = 1, Please enter a value in Field name.
| Please note: If the parameter(s) itself contain a comma (","),
it might be usefull to quote all parts of the value with " or '.
Therefore the sample above can also be written like this:
ValMinLength.name = '1', 'Please enter a value in Field
name.'
or |
In error message You can access all posted fields by quoting them in %. In addition there are some special values accessiblly with some validations. Please check this below.
| Validation name: | ValMinLength resp. ValMaxLength | |
| Number of parameters | 1 | |
| Parameter 1 | Minimum resp. maximum length of input in that field. | |
| Additional values | %currentlength% | current length of input. |
| %minlength% | Minimum length of input (ValMinLength) | |
| %maxlength% | Maximum length of input (ValMaxLength) | |
| Example of usage | ValMaxLength.text = "255", "Value in field <b>Comment</b> must be at most %maxlength% characters long. Current length: %currentlength%." | |
| Validation name: | ValIncludePattern resp. ValExcludePattern |
| Number of parameters | 1 |
| Parameter 1 | Pattern that should be ex- resp. included. This pattern is a perl compatible regular expression, with one important exception: An escape sequence must start with \\, not just \ as usual. For example: Write \\s instead of \s for a whitespace. |
| Additional values | none. |
| Example of usage | ValExcludePattern.name = "/[^a-zA-Z0-9äöüßÄÖÜâÂêÊîÎéÉ\\.\\,\\ \\-\\+*]/", "Value <b>%name%</b> in field <b>Your name</b> contains characters which are not allowed here." |
| Validation name: | ValEmailAdress |
| Number of parameters | none. |
| Additional values | none. |
| Example of usage | ValEmailAdress.email = Value <b>'%email%'</b> in field <b>Your email</b> is not a valid email adress." |
| Validation name: | ValIsInPost |
| Number of parameters | 1 - n |
| parameters | Complete list of fields, the form contains, expect from checkboxes, as they are not sent by the browser, if they are not checked. |
| Additional values | none. |
| Example of usage | ValIsInPost.fields = "subject", "message", "email", "name", "phone", "fax", "An error occured, please try again later." |
Lexasoft formmailer provides a special feature which enables You to set up different variants of a special value. For example You could define that posted value "support" can be translated to a valid email adress (support@lexasoft.de) and (the same time!) to a phrase like "support team" which could be displayed to the user.
This feature is called alias. It was developed to hide email adresses from the client in case the user has to decide, which department he would like to contact. In that case the email adress, the form is to send to, is unknown at time of development. Therefore it has to be posted. But if that, the email adress must be present in users browser, what often is not wanted due to spiders, which could use it for spaming.
Lexasoft formmailer gives You a simple tool for that. Here You will see, how it should be used:
Every alias can be defined in Your configuration file. The lines look as follows:
Alias.<FieldName>.<Variant>.<Value> = <VariantValue>
The parts have this meaning:
Alias Defines this line being alias definition. (Every alias line has to start like this) FieldName Name of the field, this entry is valid for. Variant Name of the variant. Value Posted value VariantValue Value in this variant
Here is an example:
support - team
if "support" had been posted by the user.
MailRecipients = %recipient.email%
In our sample with this the form will be sent to support@lexasoft.de, if "support" had been posted by the user.
| Please note: See the advanced sample for a complete application with that feature. |
This feature of lexasoft formmailer is particularly designed for the use of checkboxes. In html they behave in a way, that name and value of the checkbox only are transmitted, if the checkbox is checked.
If the checkbox is unchecked, nothing is transmitted at all, not even the name without a value. This might cause some problems in reacting on an unchecked checkbox.
With the default value feature You can specify a value, which is used by the formmailer if a value is not transmitted by the form, just as it is with checkboxes.
| Please note: This value will be used, if it is not transmitted, only. If it is, even with an empty value (""), the transmitted value will be used. That's why You can't use this with textfields as they are always transmitted no matter filled in or not. |
Every default value can be defined in Your configuration file. The lines look as follows:
Default.<FieldName> = <DefaultValue>
The parts have this meaning:
Default Defines this line being default definition. (Every default line has to start like this) FieldName Name of the field, this entry is valid for. DefaultValue Value to be used default.
Here is an example:
In this example value "yes" will be used, if the newsletter checkbox is checked and "no" if it is unchecked.
| Please note: See the advanced sample for a complete application with that feature. |
Substitutes are values, You do not know while designing Your form, as they will be defined at runtime, only. For example, all posted fields, configuration values in formmailer.cfg or information given in language files, can be accessed via substitutes. Simply write %SubstituteValue% in any template or configuration file.
But there are a number of reserved substitutes, that are provided by the system. You can find them in the following table:
substitute |
meaning |
|---|---|
| script | How to reach our own script. Used to define the action of the post request in form. <form method="POST" action="%script%"> |
| backlink | How to go back to form after posting. Used in ResponseTemplate. <a href="%backlink%"><font size="2">Back to the form</font></a> |
| date | Today's date in pattern You provide in Your language file. Default pattern: "m/d/Y" |
| time | Time now in pattern, You provide in Your language file, Default pattern: "H:i:s" |
| ip | Ip address of the user. |
In addition to general substitutes, upload feature makes use of several substitutes with a special meaning. As usual, all of them can be used in templates simply by writing them included in %%. In this appendix there is an overview:
substitute |
meaning |
|---|---|
| 1. Information generated by the script to be displayed in templates and messages. | |
| %UploadMaxFileSize% | Contains the maximum size of files to upload as configured in formmailer.cfg. |
| %UploadUserFilename% | The original name of the file, as sent by the user. |
| %UploadUserMimeType% | The mime type of the file, currently uploaded. |
| 2.Error messages generated by the upload module. Must be translated in lang.XXX.cfg (where XXX is the language to use). | |
| %MsgUploadFileExists% | Error message, that file to upload does exist already. Should not appear, as the formmailer always tries to find unique name for every file. |
| %MsgUploadMissingFile% | No file to upload is given. |
| %MsgUploadFileTooBig% | File to upload is larger than maximum file size. |
| %MsgUploadWrongMimeType% | Mime type of the file is not allowed to be uploaded. |
| %MsgUploadCopyError% | Uploaded file could not be copied to the specified directory. Reason may be that this directory does not exist or insufficient rights are granted. |
The upload sample is fully qualified with all substitutes above used and defined. Please check this for more details.
Changes taken place |
|
|---|---|
| v1.5.6 |
|
| v1.5.5 |
|
| v1.5.1_02 |
|
| v1.5.1 |
|