genesis-dev/landing-form

There is no license information available for the latest version (v0.1.2-beta) of this package.

v0.1.2-beta 2016-02-22 19:06 UTC

This package is not auto-updated.

Last update: 2024-11-09 18:38:19 UTC


README

#Installation

composer create-project "genesis-dev/landing-form":"v0.1.1-beta" landing-form

#Configuring /config/local.php - overwrites /config/main.php (using array_merge_recursive)

<?php
return [
    "db" => [ // Database settings
        'database_type' => '',
        'database_name' => '',
        'server' => '',
        'username' => '',
        'password' => '',
        'charset' => 'utf8',
    ],
    "telegram" => [ // Telegram settings
        "api_key" => "",
    ],
    "defaults" => [
        "mailer" => [ // SMTP settings
            "host" => '',
            "username" => '',
            "password" => '',
            "from" => '',
            "fromName" => "",
            "subject" => "",
            "to" => ["mail@example.com", "mail2@example.com"],
        ],
        "telegram" => [
            "channel_name" => "", // Telegram channel name (without @)
            "include" => ["email", "phone"], // Names of fields to include in messages
        ],
    ],
    "sites" => [
        "siteID" => [ // Array, similar structure to defaults and overwrites them. Key is siteID.
        ],
        "test_null" => [ // Configurations for tests
            "mailer" => false,
        ],
        "test_mail" => [
        ],
        "test_telegram" => [
            "mailer" => false,
            "telegram" => [
                "channel_name" => "genesis_orders",
            ],
        ],
        "test_all" => [
            "telegram" => [
                "channel_name" => "genesis_orders",
            ],
        ],
    ],
];

/config/main.php

<?php
$config = [
    "defaults" => [
        "validators" => [
            "email" => function($str, $fields, $validators) { // $str - field value, $fields - other fields, $validators - other validators
                return !empty($str) && filter_var($str, FILTER_VALIDATE_EMAIL);
            },
            "phone" => function($str, $fields, $validators) {
                return !empty($str) && preg_match('/^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$/', $str);
            },
        ],
    ],
    "table" => "landing_form", // Table name in DB
];

//......

#Usage

<!-- After jQuery script tag -->
<script src="<path_to_client_folder>?siteID=<siteID_from_config>&success_callback=<name_of_function>" defer></script>

<!-- Form markup -->
<form action="<path_to_service_root>" method="get" data-landing-form>
    <input type="text" name="landingForm[email]">
    <input type="text" name="landingForm[phone]">
    <input type="submit" value="Submit">
</form>