Tutorial

Install Pancake PHP

Follow these steps to install Pancake PHP:

  1. Download Pancake PHP from Bitbucket.
  2. Unzip the downloaded archive.
  3. Upload the Pancake directory to a location on your PHP include path.

If you want to utilise Pancake’s included CSS and JavaScript files, you need to perform the additional following two steps:

  1. Copy or symlink the Pancake/Resources/css and Pancake/Resources/js directories to public file paths.
  2. Modify the settings in Pancake/Settings/Other.php as appropriate.

Create the form

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() ?>

Add fields to the form

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() ?>
_images/tutorial-1.png

Process the form

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() ?>

Table Of Contents

Previous topic

Pancake PHP documentation

Next topic

Topics

This Page