Follow these steps to install Pancake PHP:
If you want to utilise Pancake’s included CSS and JavaScript files, you need to perform the additional following two steps:
First, include Pancake in your PHP file. Pancake uses a class autoloader, so you only need to include the Pancake/Pancake.php file.
<?php
include_once 'Pancake/Pancake.php';
?>
Next, create an instance of Pancake\Pancake. You can name the variable whatever you would like, but $form is the convention.
<?php
$form = new Pancake\Pancake;
?>
A Pancake form is enclosed in calls to the Pancake::start() and Pancake::end() methods:
<?= $form->start() ?>
// Form contents...
<?= $form->end() ?>
After having completed these three steps, you should have the following:
<?php
include_once 'Pancake/Pancake.php';
$form = new Pancake\Pancake;
?>
<?= $form->start() ?>
// Form contents...
<?= $form->end() ?>
To add a field to your form, call the appropriate method on your Pancake form instance. Each field must have a unique name, which is always the first argument of the method call.
<?php
include_once 'Pancake/Pancake.php';
$form = new Pancake\Pancake;
?>
<?= $form->start() ?>
<fieldset>
<legend>Register</legend>
<?= $form->text('first_name') ?>
<?= $form->text('middle_name', array(
'required' => false
)) ?>
<?= $form->text('last_name') ?>
<?= $form->email('email_address') ?>
</fieldset>
<?= $form->submit('submit', 'Apply') ?>
<?= $form->end() ?>
You can specify hooks that process the form after it passes validation. These hooks can be used to email the submitted form data, send a confirmation email, and much more.
<?php
include_once 'Pancake/Pancake.php';
$form = new Pancake\Pancake;
$form->addHook(
'after',
'EmailForm',
array(
'to' => 'example@example.com',
'from' => 'email'
)
);
?>
<?= $form->start() ?>
<fieldset>
<legend>Register</legend>
<?= $form->text('first_name') ?>
<?= $form->text('middle_name', array(
'required' => false
)) ?>
<?= $form->text('last_name') ?>
<?= $form->email('email_address') ?>
</fieldset>
<?= $form->submit('submit', 'Apply') ?>
<?= $form->end() ?>