PHP code example of simfatic / formhandler

1. Go to this page and download the library: Download simfatic/formhandler 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/ */

    

simfatic / formhandler example snippets


use Simfatic\FormHandler\FormHandler;

$fh = new FormHandler(); 

$fh->validate(function($validator)
{
	$validator->field('name')->isRequired();
	$validator->field('email')->isEmail()->isRequired();

})->sendEmailTo('[email protected]');


echo $fh->process($_POST);

use Simfatic\FormHandler\FormHandler;

$fh = new FormHandler(); 

$fh->validate(function($validator)
{
	$validator->field('name')->isRequired();
	$validator->field('email')->isEmail()->isRequired();

})->configMailer(function($mailer)
{
	$mailer->setFrom('[email protected]','Form',false);
	
	$mailer->isSMTP();                                    // Send using SMTP
    $mailer->Host       = 'smtp.example.com';             // Set the SMTP server to send through
    $mailer->SMTPAuth   = true;                           // Enable SMTP authentication
    $mailer->Username   = '[email protected]';             // SMTP username
    $mailer->Password   = 'secret';                       // SMTP password
    $mailer->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
	$mailer->Port       = 587;   
	
	/*
	Example: adding Cc
	$mail->addCC('[email protected]');
	*/
	
})->sendEmailTo('[email protected]');


echo $fh->process($_POST);

$fh = new FormHandler(); 

$fh->validate(function($validator)
{
    $validator->field('name')->isRequired();
    $validator->field('email')->isEmail()->isRequired();

})->attachFiles(['image'])
->sendEmailTo('[email protected]');

use Simfatic\FormHandler\FormHandler;

$pp = new FormHandler(); 

$pp->validate(function($validator)
{
	$validator->field('name')->isRequired();
	$validator->field('email')->isEmail()->isRequired();
})
->