2017 © Pedro Peláez
 

package formchecker

Checks form fields and generates html-table to mail it to administrator

image

romash1408/formchecker

Checks form fields and generates html-table to mail it to administrator

  • Wednesday, February 21, 2018
  • by romash1408
  • Repository
  • 1 Watchers
  • 0 Stars
  • 34 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 6 % Grown

The README.md

FormChecker

Description

Makes similar checking of form fields filled on your web site. It verifies required fields, including email addresses (checks @ existing and hostname MX record).
After that html report is generated and sent by mail(), or user custom function, callback called with filtered fields and autosend is sent by same method., (*1)

Install

Via Composer, (*2)

``` bash $ composer require romash1408/formchecker, (*3)


## Example ``` php require "vendor/autoload.php"; use R14\FormChecker; use R14\FormException; $usermail; $checker = new FormChecker( $forms = [ "mainform" => [ "subject" => "Test main form", "fields" => [ "name" => [ "placeholder" => "Name", ], "phone" => [ "type" => "tel", "placeholder" => "Phone number", "required" => true, ], "email" => [ "type" => "email", "placeholder" => "E-mail", "required" => true, ], "list" => [ "type" => "list", "placeholder" => "List", "required" => true, "list" => [ "One", "Two", "Three", ], ], ], "callback" => function($fields) use(&$usermail) { $usermail = $fields["email"]; // We can send post request with filtered and checked data to CRM server, if needed // $fields["key"] = "123456"; // Formsender::post("https://crm-server.com", $fields); }, "autosend" => [ "template" => function() { return <<<HTML

Thank you for your request!

HTML; }, "address" => function() use(&$usermail) { return [ $usermail ]; }, "subject" => function() { return "Answer to user"; }, ], "to" => [ "admin@server" ], ], "contactform" => [ "subject" => "Contact form", "fields" => [ "author" => [ "type" => "email", "placeholder" => "Author e-mail", "required" => true, ], "message" => [ "type" => "textarea", "placeholder" => "Message", "required" => true, ], ], "to" => [ "moder@gmail.com" ], ], ], $config = [ "send" => function ($mail) { echo ' <h2>Sending mail to ' . implode(", ", $mail["to"]) . ' with subject "' . $mail["subject"] . '"</h2> ' . $mail["body"] . ' '; }, ] );

Now we have $checker variable with information about all our forms and send function. To make magic just call $checker->work() with formname ("default" by default) and form fields array ($_POST + $_FILES by default), like this:, (*4)

try
{
    $checker->work($_POST["formname"]);
}
catch (FormException $e)
{
    echo '<h2 style="color: red">' . $e->getMessage() . '</h2>';
}

#1

``` php $_POST = [ "formname" => "mainform", ];, (*5)


#### Output: > ![Field Phone number must not be empty](https://romash1408.ru/untouchable/github-formchecker/readme/EMPTY_FIELD.jpg "Field Phone number must not be empty") ### #2 ``` php $_POST = [ "formname" => "mainform", "phone" => "+7 (999) 999-99-9", "email" => "test", ]; try { $checker->work($_POST["formname"]); } catch (FormException $e) { echo '<h2 style="color: red">' . $e->getMessage() . '</h2>'; }

Output:

Incorrect phone number format, (*6)

#3

``` php $_POST = [ "formname" => "mainform", "phone" => "+7 (999) 999-99-99", "email" => "test@gmail.co", ];, (*7)

try {, (*8)

$checker->work($_POST["formname"]);

} catch (FormException $e) {, (*9)

echo '<h2 style="color: red">' . $e->getMessage() . '</h2>';

}, (*10)


#### Output: > ![Incorrect email address format](https://romash1408.ru/untouchable/github-formchecker/readme/WRONG_EMAIL.jpg "Incorrect email address format") ### #4 ``` php $_POST = [ "formname" => "mainform", "name" => "Tester", "phone" => "+7 (999) 999-99-99", "email" => "test@gmail.com", ]; try { $checker->work($_POST["formname"]); } catch (FormException $e) { echo '<h2 style="color: red">' . $e->getMessage() . '</h2>'; }

Output:

Field List must not be empty, (*11)

#5

``` php $_POST = [ "formname" => "mainform", "name" => "Tester", "phone" => "+7 (999) 999-99-99", "email" => "test@gmail.com", "list" => [ "One", "Four", ], ];, (*12)

try {, (*13)

$checker->work($_POST["formname"]);

} catch (FormException $e) {, (*14)

echo '<h2 style="color: red">' . $e->getMessage() . '</h2>';

}, (*15)


#### Output: > ![Did not found Four in List](https://romash1408.ru/untouchable/github-formchecker/readme/WRONG_LIST.jpg "Did not found Four in List") ### #6 ``` php $_POST = [ "formname" => "mainform", "name" => "Tester", "phone" => "+7 (999) 999-99-99", "email" => "test@gmail.com", "list" => [ "One", "Three", ], ]; try { $checker->work($_POST["formname"]); } catch (FormException $e) { echo '<h2 style="color: red">' . $e->getMessage() . '</h2>'; }

Output:

Result of sending main form, (*16)

#7

``` php $_POST = [ "formname" => "contactform", "author" => "work@romash1408.ru", "message" => <<htmlspecialchars, Su users can not TEXT ];, (*17)

try {, (*18)

$checker->work($_POST["formname"]);

} catch (FormException $e) {, (*19)

echo '<h2 style="color: red">' . $e->getMessage() . '</h2>';

} ```, (*20)

Output:

Result of sending contact form, (*21)

The Versions

21/02 2018

dev-master

9999999-dev

Checks form fields and generates html-table to mail it to administrator

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Avatar romash1408

21/02 2018

v1.0.2

1.0.2.0

Checks form fields and generates html-table to mail it to administrator

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Avatar romash1408

13/11 2017

v1.0.1

1.0.1.0

Checks form fields and generates html-table to mail it to administrator

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Avatar romash1408

09/11 2017

v1.0.0

1.0.0.0

Checks form fields and generates html-table to mail it to administrator

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Avatar romash1408