Skip to content
This repository was archived by the owner on Jul 7, 2023. It is now read-only.

Layouts

Domagoj Gojak edited this page Aug 26, 2015 · 8 revisions

Every form needs to render in one form or another and in order to this process as simple as possible Formjack allows you to use built-in layouts, but, it also allows you to build your own if you wish to do so.

Background

Every time you invoke the render or the renderField method, Formjack will render those fields by calling the renderField method of a layout instance, and it will do that for each field within the form (in case you've invoked the render method). Layout then sets up wrappers around the field and renders the field and label (if defined) within that wrapper by calling the render (or renderChoice) and renderLabel methods of that same field instance. After that, HTML code gets returned to the caller function and the caller function then prints out the HTML contents.

Usage

In order to use a layout you will first need to create a new Formjack\Form instance.

<?php

use Formjack\Form;

$form = new Form( /* ... */ );

After that you can apply a custom or a build in layout simply by calling the setLayout() method and passing in the layout instance.

<?php

// ...

use My\App\CustomLayout;

$form = new Form( /* ... */ );
$form->setLayout(new CustomLayout());

If you don't define which layout should the form use, Formjack will use the built-in \Formjack\Layout\DefaultLayout layout.

Built-in Layouts

  • \Formjack\Layout\DefaultLayout - default layout

More layouts comming soon!

Custom Layouts

You can easily create and use your own custom layouts just by extending the \Formjack\Layout\AbstractLayout abstract class or by extending the provided \Formjack\Layout\DefaultLayout. In order to get a better understanding on how layouts really work take a closer look at the built-in \Formjack\Layout\DefaultLayout layout.

Clone this wiki locally