The Reusable Forms Customization GuideWhen you download a form, the file "handler.php" already has a basic implementation ready for you. This guide explains how to customize handler.php.
See a video demo here
Update your email address to receive form submission emails
$pp->sendEmailTo('email@example.com'); // ← Your email here
replace firstname.lastname@example.org with your email address.If you want to send email to more than one email addresses, just enter it as an array like so:
Adding Form ValidationsAdd your validations in the validate() function. You can add more validations as required. Examples:
$validator = $pp->getValidator(); $validator->fields(['name','email'])->areRequired()->maxLength(50); $validator->field('email')->isEmail(); $validator->field('message')->maxLength(6000);
Customizing PHPMailerThe FormHandler uses PHPMailer to send emails. You can customize the internal PHPMailer object like so:
$mailer = $pp->getMailer(); $mailer->setFrom('email@example.com','Form',false);
Using an SMTP accountYou can customize PHPMailer to use an SMTP account too. The snippet below uses SMTP account from Amazon SES:
$mailer = $pp->getMailer(); //Using Aamazon AWS SES SMTP account $mailer->IsSMTP(); $mailer->SMTPAuth = true; $mailer->SMTPSecure = "tls"; $mailer->Host = "email-smtp.us-east-1.amazonaws.com"; $mailer->Username = "YOUR AWS SMTP CREDENTIALS"; $mailer->Password = "YOUR AWS SMTP CREDENTIALS"; $mailer->setFrom('firstname.lastname@example.org', 'Form');
See the PHPMailer Page for more customization options.
File UploadsIf you have file uploads in the form, just call attachFiles() with the name of the file input field to attach the file to the email.
where 'image' is the name of the file upload field
CaptchaYou can use Gregwar/Captcha to add captcha to your form. Call requireCaptcha() function so that the validation is triggered.
See some sample forms that use this captcha
ReCaptchaAlternative to the image captcha, you can add ReCaptcha to the form as well. First you have to signup with reCaptcha and get your secret key.
Then Enable ReCaptcha and setup your secret Key.
$pp->requireReCaptcha(); $pp->getReCaptcha()->initSecretKey('Your ReCaptcha Secret Key Here');
You can download some recaptcha forms in this page.
Questions? post it here.