承接 romash1408/formchecker 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

romash1408/formchecker

Composer 安装命令:

composer require romash1408/formchecker

包简介

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

README 文档

README

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.

Install

Via Composer

$ composer require romash1408/formchecker

Example

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
<h3>Thank you for your request!</h3>
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:

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

#1

$_POST = [
    "formname" => "mainform",
];

Output:

Field Phone number must not be empty

#2

$_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

#3

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

try {

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

} catch (FormException $e) {

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

}

Output:

Incorrect email address format

#4

$_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

#5

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

try {

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

} catch (FormException $e) {

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

}

Output:

Did not found Four in List

#6

$_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

#7

$_POST = [
    "formname" => "contactform",
    "author" => "work@romash1408.ru",
    "message" => <<<TEXT
Helo, this is a test of FormChecker.
It is using <a href='http://php.net/manual/ru/function.htmlspecialchars.php'>htmlspecialchars</a>,
Su users can not <script>hack(you);</script>
TEXT
];

try {

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

} catch (FormException $e) {

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

}

Output:

Result of sending contact form

统计信息

  • 总下载量: 248
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-11-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固