1. Go to this page and download the library: Download justcoded/form-handler library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
justcoded / form-handler example snippets
// init autoload.
ler\FormHandler;
use JustCoded\FormHandler\Handlers\MailHandler;
use JustCoded\FormHandler\DataObjects\MailMessage;
use JustCoded\FormHandler\FileManager\FileManager;
$mailer = new MailHandler($mailerConfig, new MailMessage($messageConfig));
$form = new FormHandler($validationRules, $mailer);
if ($form->validate($_POST)) {
$form->process();
}
$result = $form->response();
// TODO: do somethign with the results. For example write to a session and redirect back.
$validationRules = [
'fields' => [
'name' => ['> [
' for mapFieldsRules().
'labels' => [
'name' => 'Name',
'email' => 'Email address',
'message' => 'Message',
] // according to Valitron doc for labels().
];
// PHPMailer config:
$mailerConfig = [
'mailer' => MailHandler::USE_PHPMAILER,
'host' => 'SMTP HOST', // set your smtp host.
'user' => 'YOUR EMAIL', // set email.
'password' => 'YOUR PASSWORD', // set password.
'protocol' => 'tls', // 'tls', 'ssl' or FALSE for not secure protocol/
'port' => 587, // your port.
];
// Mandrill config:
$mailerConfig = [
'mailer' => MailHandler::USE_MANDRILL,
'apiKey' => 'YOUR API KEY', // set correct API KEY.
];
// set cookie with form status/errors and redirect back
setcookie('form_status', $form->response());
header('Location: index.php');
exit;
// start session if not started:
session_start();
// set sesson with form status/errors and redirect back
$_SESSION['form_status'] = $form->response();
header('Location: index.php');
exit;
// Configure the location of attachments directory
// it should be writable and accessible from browser
$fileManager = new FileManager([
'uploadPath' => __DIR__ . '/attachments', // folder path to save files to
'uploadUrl' => 'http://MY-DOMAIN.COM/attachments', // site URL to this folder
]);