Forms

Usage

{!! PageBuilder::block($block_name, $options) !!}

ie. {!! PageBuilder::block('contact_form') !!}

Method Options ($options)

'url' => '/contact' (default: submits to same page, set to something else to change)

'files' => false (default: true, accept file inputs)

'id' => 'contact-form' (default: form[block_id], can set the id of the form)

uses laravel collective's form open function, other option variables will be passed through to this

Template Locations

/blocks/forms/[form_template].blade.php

form_template can be set in the admin when editing the form's settings

Available Variables

The following variables contain data set in the admin and can be used in the form template

$form_data->email_from (string)

$form_data->email_to (string)

$form_data->template (string - template name without the .blade.php)

$form_data->page_to (int - page id)

$form_data->captcha (bool)

Examples

Creating forms in Coaster is refreshingly easy, they can be as complex or simple as you like and utilise just about any valid HTML5 input element. By default Coaster ships with a contact form of which we will use to form the basis of this tutorial. The code below has been taken from the contact.blade.php file found in /blocks/forms:

<h3>Contact Form:</h3>

<div class="form-group {!! FormMessage::get_class('email') !!}">
    {!! Form::text('email', Request::get('email'), array('class' => 'form-control', 'placeholder' => 'Enter your email')) !!}
    <span class="help-block">{!! FormMessage::get_message('email') !!}</span>
</div>

<div class="form-group {!! FormMessage::get_class('name') !!}">
    {!! Form::text('name', Request::get('name'), array('class' => 'form-control', 'placeholder' => 'Enter your Name')) !!}
    <span class="help-block">{!! FormMessage::get_message('name') !!}</span>
</div>

<div class="form-group {!! FormMessage::get_class('message') !!}">
    {!! Form::textarea('message', Request::get('message'),  array('rows' => 3, 'class' => 'form-control', 'placeholder' => 'Your Message ...')) !!}
    <span class="help-block">{!! FormMessage::get_message('message') !!}</span>
</div>

@if ($form_data->captcha)
<div class="form-group {!! FormMessage::get_class('captcha_code') !!}">
    <div class="clearfix"></div>
    <div class="pull-left">
        <img id="captcha" src="{!! URL::to('packages/webfeet/cms/securimage/securimage_show.php') !!}" alt="CAPTCHA Image"  />
    </div>
    <div class="pull-left" style="padding-left: 20px">
        <a href="#" onclick="document.getElementById('captcha').src = '{!! URL::to('packages/webfeet/cms/securimage/securimage_show.php') !!}?' + Math.random(); return false">[ Refresh Captcha ]</a>
        <object type="application/x-shockwave-flash" data="{!! URL::to('packages/webfeet/cms/securimage/securimage_play.swf') !!}?audio_file={!! URL::to('/packages/webfeet/cms/securimage/securimage_play.php') !!}" width="19" height="19">
            <param name="movie" value="{!! URL::to('packages/webfeet/cms/securimage/securimage_play.swf') !!}?audio_file={!! URL::to('/packages/webfeet/cms/securimage/securimage_play.php') !!}&amp;bgColor1=#fff&amp;bgColor2=#fff&amp;iconColor=#777&amp;borderWidth=1&amp;borderColor=#000" />
        </object>
        <p><input id="captcha_code" class="form-control" type="text" name="captcha_code" size="10" maxlength="6" style="width:100px" /> <span class="help-block">{!! FormMessage::get_message('captcha_code') !!}</span></p>
    </div>
</div>
@endif

<div class="control-group">
    <div class="controls">
        {!! Form::submit('Submit', array('class' => 'btn btn-default')) !!}
    </div>
</div>

Forms in Coaster use the form functions by Laravel Collective, a new form input can be instantiated by calling the Form class followed by the input of your choice. For example, a basic text input would be called by using:

{!! Form::text('text', Request::get('text')) !!}

Captcha Codes (Optional)

Coaster gives you the option of enabling captcha code submissions on an individual basis for each one of your forms. This functionality is entirely optional and you can choose to not allow the functionality on your form by removing $form_data->captcha conditional. If however, you wish to retain this functionality you must ensure the HTML surrounding it is supported within your theme or else once enabled it may break your design. The captcha input must be named captcha_code.

Form Rules

In the theme admin section, you can manage select fields via the "Manage form input validation rules" link. In order to add validation rules for any of your forms, you just need to add the form name, field name, and rules into this table.

For example, add 'email with the rules email|required' to the table in the manage rules section and any form with an input named 'email' will require and validate that email address. 

The validation rules are based on the format of Laravel's form Rules.

Modern Framework

Based on Laravel 5

Constant development

Additional features always being planned/researched

Open source

"git" involved

Latest from the blog


read more


read more


read more