Skip to content

Commit 4aa04e5

Browse files
committed
Merge remote-tracking branch 'origin/feature/16410927_documentation' into feature/16410927_documentation
2 parents 6aff494 + 0b77872 commit 4aa04e5

1 file changed

Lines changed: 44 additions & 35 deletions

File tree

README.md

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,59 @@
11
<p align="center">
2-
<h1 align="center">Form2email</h1>
3-
<br>
2+
<h1 align="center">Static forms FormHandler library</h1>
43
</p>
54

6-
This library allows you rapidly implement contact forms on your site.
5+
Small library to validate simple html forms data and send requests to email.
6+
Furthermore you can write your own "handler" to process valid data, for example if you need to save
7+
it through API to a 3d-party service like Mailchimp, SalesForce, CRM system, etc.).
78

8-
## 1. Installation
9+
## Why FormHandler
910

10-
### 1.1 Install via Composer (preferable)
11+
It's very easy to find some ready-to-use solution to process a contact form. Usually this is pure PHP
12+
script, which collect data and send email with php `mail()` function. It's not bad, but you can find
13+
numerous problems with such scripts:
1114

12-
The recommended way to install Form2email is through
13-
[Composer](http://getcomposer.org).
15+
* `mail()` function can be blocked on production server, because it's not secure. Also it's often goes to SPAM folder, when you use `mail()` function.
16+
* You need to validate, that the data is valid. Manual validation of the `$_POST` array is time consuming and require knowledge of PHP, RegExp's knowledge etc.
1417

15-
If you do not have [Composer](http://getcomposer.org/), you may install it by following the instructions
16-
at [getcomposer.org](http://getcomposer.org/doc/00-intro.md#installation-nix).
18+
We decide to create small library, which fix all these issues, so to process a form you need:
1719

18-
You can then install Form2email using the following command:
20+
* set validation rules with simple configuration array
21+
* set your Mail settings (SMTP settings OR Mandrill API key)
22+
* set your message params (From, To, Subject, Body template)
1923

20-
~~~
21-
1. Create folder
22-
2. Create composer.json file (if it doesn't exist) with json record:
24+
And that's it!
2325

24-
{
25-
"require": {
26-
"monolog/monolog": "1.0.*"
27-
}
28-
}
26+
## Requirements
27+
28+
* PHP 7.0+
29+
* [Composer](http://getcomposer.org/)
30+
31+
## Usage
32+
33+
Imagine you have simple html website with a contact form and you want to process it. We will guide you
34+
through the whole process of creating PHP script to process a form request.
2935

30-
3. composer create-project
36+
### Init your environment
3137

32-
4. composer require justcoded/form-handler
33-
~~~
34-
### 1.2 Install by download directly (alternative)
38+
We suggest to create separate folder to place code into it. Let's call it `form`.
39+
File structure will looks like this:
40+
41+
|- /form/ # folder for our code
42+
|- contact.php # simple HTML page with a form
43+
44+
Inside `/form/` folder we need to create `composer.json` file to set our library requirement:
45+
46+
{
47+
"require": {
48+
"justcoded/form-handler": "^1.0.*"
49+
}
50+
}
3551

36-
### 1.2.1 Clone the project
37-
~~~
38-
git clone https://github.com/justcoded/form-handler.git
39-
~~~
40-
### 1.2.2 Install dependency
41-
~~~
42-
cd form-handler
52+
Now we need to download all required files with a composer, by running a bash command:
4353

44-
composer install
45-
~~~
54+
composer install
4655

47-
## 2. Contact form
56+
### 2. Contact form
4857
Create contact form with 'action' attribute where to send the form-data when a form is submitted. You can implement
4958
multiple forms. You can find an example in the file examples/index.php
5059

@@ -60,7 +69,7 @@ multiple forms. You can find an example in the file examples/index.php
6069
</form>
6170
```
6271

63-
## 3. Entry file
72+
### 3. Entry file
6473

6574
You must create entry file handler for created contact form. To do this, copy the file
6675
form2email-basic.php or form2email-mandrill.php from the Example folder to the root of the site.
@@ -72,7 +81,7 @@ After that in the /path/to/form2email-basic.php file, include the path to the fi
7281
require __DIR__ . '/../vendor/autoload.php';
7382
```
7483

75-
## 4. Configuration
84+
### 4. Configuration
7685

7786
In the action file (path/to/form2email-basic.php), we must write a configuration of validation, mailer and message:
7887
For validation of text fields we use [Valetron](https://github.com/vlucas/valitron#built-in-validation-rules) library.
@@ -142,7 +151,7 @@ $message = [
142151
];
143152
```
144153

145-
## 5. Template
154+
### 5. Template
146155
You can customize the email templates. You can place the form fields anywhere. To do this, put the name of the form
147156
field in curly braces. For example, in the file 'template-html.php':
148157

0 commit comments

Comments
 (0)