-
Notifications
You must be signed in to change notification settings - Fork 4
Layouts
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.
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.
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.
- \Formjack\Layout\DefaultLayout - default layout
More layouts comming soon!
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.