16

## Forms Example PHP >= 5.4

form validation blade html bootstrap foundation emmet

Forms is a utility class that builds web forms in one of the following in built styles

- Plain Html 5
- Twitter Bootstrap 3
- Zerb Foundation 5

    use Luracast/Restler/UI/Forms;
    use Luracast/Restler/UI/FormStyles;

    Forms::$style = FormStyles::$bootstrap3; // FormStyles::$foundation5;

Where ever you need the generated forms (typically in view templates) just call

    echo Forms::get('POST','user/signup');

If you are using twig templates you can use the following instead

    {{ form('POST', 'user/signup') }}

## Emmet Templates

Forms is using Emmet templates, with which adding more styles is very easy

Emmet Templates is built with a subset of Emmet as in emmet.io extended to serve as a template engine

For example

    .form-group>label{$label#}+input.form-control[value=$value# type=$type#

Expands to the following html

    <div class="form-group">
        <label>Email</label>
        <input class="form-control" value="arul@luracast.com" type="email"/>
    </div>

When the given data is

    array(
        'label' => 'Email',
        'value' => 'arul@luracast.com',
        'type' => 'email'
    );

Typically this data is supplied by the metadata extracted from the php-doc comments of of the api parameters

Users.php and Address.php shows the bare minimum code needed to get create forms.

Check out the resulting form here. We have made it easy to try different styles Also this example serves as an example for our Blade template integration

See bootstrap3.blade.php and foundation5.blade.php

> This API Server is made using the following php files/folders

> - index.php (gateway)
> - Users.php (api)
> - Address.php (helper)
> - restler.php (framework)
> - HtmlFormat.php (format)
> - JsonFormat.php (format)

This API Server exposes the following URIs

    GET  users        ⇠ Users::index()
    POST users/signin ⇠ Users::postSignIn()
    POST users/signup ⇠ Users::postSignUp()