2017 © Pedro Peláez
 

library formfields

Laravel 5 form fields HTML generator sourced from Blade template engine views.

image

markhilton/formfields

Laravel 5 form fields HTML generator sourced from Blade template engine views.

  • Friday, July 15, 2016
  • by jbravo
  • Repository
  • 1 Watchers
  • 0 Stars
  • 100 Installations
  • HTML
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

FormFields

FormFields is a collection of editable Laravel Blade views to render bootstrap responsive HTML content for individual form fields. The form configuration is fetched from ORM model., (*1)

It also contains a class to queue linked and inline supporting javascripts., (*2)

Main features

  • read form fields configurtion directly from ORM models
  • render individual HTML content for form fields
  • support for required javascripts included in form fields template
  • support for Laravel Blade template engine

Setup

Add to your config/app.php, (*3)

'providers' => [
    ...
    MarkHilton\FormFields\FormFieldsServiceProvider::class,
],

'aliases' => [
    ...
    'jsQueue'     => MarkHilton\FormFields\jsQueue::class,
    'FormBuilder' => MarkHilton\FormFields\FormBuilder::class,
],

inside app root folder copy config file:, (*4)

cp vendors/markhilton/formfields/config/formfields.php configs/formfields.php

Model

class Your_Model_Name extends Model
{
    public static $errors = [];

    // ... //

    // HTML form builder definitions
    public static $form = [
        'name' => [ 
            'type'         => 'input',
            'label'        => 'Label name',
            'position'     => 'top',
        ],

        'status'           => [ 
            'type'         => 'select',
            'label'        => 'Status',
            'position'     => 'side',
            'choice'       => [
              'active'   => 'Active',
              'pending'  => 'Pending',
              'suspended'=> 'Suspended',
            ],
            'default'      => 'active',
        ],

    // ... //

Controller

namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use App\Your_Model_Name;
use Illuminate\Http\Request;

class SiteController extends Controller {

    public function create(Request $request)
    {
        $form = \FormBuilder::build(Your_Model_Name::$form, $request->old() ? $request->old() : []),

        return view('layout', $form);

    // ... //

View



{{ $status }} {{ $name }}

HTML output



Usage

Queue for linked and inline javascripts inside view template, (*5)

Controller

  • jsQueue::push('[javascript code]'); to push javascripts code to the queue
  • jsQueue::link('[javascript file]'); to add linked javascripts files

View

add {{ jsQueue::render() }} call in template header or footer in order to render queued javascripts, (*6)

How to steps

  1. Define $form property in ORM model
  2. Assign HTML form fields output from \FormBuilder::build(ORM_MODEL::$form);
  3. Render form field in the template with {{ $field_name }}

The Versions

15/07 2016

dev-master

9999999-dev http://github.com/markhilton/formfields

Laravel 5 form fields HTML generator sourced from Blade template engine views.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Mark Hilton

form html forms templates fields