A powerful form builder, for Laravel and other frameworks (stand-alone too)

Overview

Former

A Laravelish way to create and format forms

Build Status Latest Stable Version Total Downloads

Former outputs form elements in HTML compatible with your favorite CSS framework (Bootstrap and Foundation are currently supported). Former also handles repopulation after validation errors, including automatically rendering error text with affected fields.

Introduction

Former provides a fluent method of form creation, allowing you to do:

Former::framework('TwitterBootstrap3');

Former::horizontal_open()
  ->id('MyForm')
  ->rules(['name' => 'required'])
  ->method('GET');

  Former::xlarge_text('name') # Bootstrap sizing
    ->class('myclass') # arbitrary attribute support
    ->label('Full name')
    ->value('Joseph')
    ->required() # HTML5 validation
    ->help('Please enter your full name');

  Former::textarea('comments')
    ->rows(10)
    ->columns(20)
    ->autofocus();

  Former::actions()
    ->large_primary_submit('Submit') # Combine Bootstrap directives like "lg and btn-primary"
    ->large_inverse_reset('Reset');

Former::close();

Every time you call a method that doesn't actually exist, Former assumes you're trying to set an attribute and creates it magically. That's why you can do in the above example ->rows(10) ; in case you want to set attributes that contain dashes, just replace them by underscores : ->data_foo('bar') equals data-foo="bar". Now of course in case you want to set an attribute that actually contains an underscore you can always use the fallback method setAttribute('data_foo', 'bar'). You're welcome.

This is the core of it, but Former offers a lot more. I invite you to consult the wiki to see the extent of what Former does.


Installation

Require Former package using Composer:

composer require anahkiasen/former

Publish config files with artisan:

php artisan vendor:publish --provider="Former\FormerServiceProvider"

App.php config for Laravel 5.4 and below

For Laravel 5.4 and below, you must modify your config/app.php.

In the providers array add :

Former\FormerServiceProvider::class

Add then alias Former's main class by adding its facade to the aliases array in the same file :

'Former' => 'Former\Facades\Former',

Table of contents

Comments
  • Configurable URL absolute or relative paths

    Configurable URL absolute or relative paths

    Enabled relative URL support with config param and as a function param. Keeping the same behavior as Laravel route and action helper functions. As a fallback, it keeps the original behavior of always returning absolute paths;

    opened by gpassarelli 4
  • Multiple attributes treated differently from single attribute in queryToArray

    Multiple attributes treated differently from single attribute in queryToArray

    https://github.com/formers/former/blob/d8cf68fce36770646237ce92d7cf86576c1bdebf/src/Former/Helpers.php#L188-L193

    This code forces the string type:

    • to the text when single attribute
    • to the attribute value on multiple attributes (and not to the text in this case)

    It was detected when adding a new attribute to select options, which until then only had the typical value. When populating the default selected option, it would fail because the populated value was an int but the value was now a string. I workaround it by casting the default selected value to a string when calling populateField, but it would be better to fix Former.

    Proposed fix:

    //For backward compatibility 
    if (count($attributes) === 1) { 
        $array[$optionAttributeValue] = (string) $optionText; 
    } else { 
        $array[(string) $optionText][$optionAttributeName] = $optionAttributeValue; 
    } 
    

    P.S.: I only come into contact with Former through another project so I might be completely missing something here, my apologies if so.

    opened by OXINARF 0
  • Bootstrap 4 Framework uses wrong classes for input group & no classes for checkbox

    Bootstrap 4 Framework uses wrong classes for input group & no classes for checkbox

    There were currently two bugs with the Bootstrap 4 framework. Tested in Bootstrap v4.1.3 and v4.3.1 (latest) and used in Laravel 5.7.*

    Input Group with Append

    Problem: appended/prepended text is not displaying correctly because of wrong class "input-group-addon".

    Line used:

    Former::text('test')->append('€');
    

    Renders:

    <div class="form-group">
     <div class="input-group">
      <input class="form-control" id="test" type="text" name="test">
      <span class="input-group-addon">€</span>
     </div>
    </div>
    

    Expected:

    <div class="form-group">
      <div class="input-group">
        <input class="form-control" id="test" type="text" name="test">
        <div class="input-group-append">
          <span class="input-group-text">€</span>
        </div>
      </div>
    </div>
    

    Checkbox

    Problem: small displaying tweaks because of missing classes for input and label.

    Line used:

    Former::checkbox('test')->text('Test');
    

    Renders:

    <div class="form-group">
      <div class="form-check">
        <input id="test" type="checkbox" name="test" value="1">
        <label for="test" class="">Test</label>
      </div>
    </div>
    

    Expected:

    <div class="form-group">
      <div class="form-check">
        <input class="form-check-input" id="test" type="checkbox" name="test" value="1">
        <label for="test" class="form-check-label">Test</label>
      </div>
    </div>
    
    opened by marvinschroeder 8
  • Custom Rule classes not working

    Custom Rule classes not working

    Hi!

    This seems like dumb question, but are custom rule classes supported by Former?

    I'm getting the following error when I try to pass my form request rules to Former:

    strpos() expects parameter 1 to be string, object given
    

    This happens in the Former.php file on line 315:

    foreach ($expFieldRules as $rule) {
        $parameters = null;
     
        if (($colon = strpos($rule, ':')) !== false) {   // <-------------------
             $rulename = substr($rule, 0, $colon);
    ...
    }
    

    To me it seems like there's a check on rule objects missing.

    Thanks!

    Feature Request 
    opened by KuenzelIT 1
  • Prepending prevents Field Error display

    Prepending prevents Field Error display

    If you prepend a link to a text field, after Validation with errors there is no error dispay in the form. Without prepending, the display works fine.

    Former::text('file')->prepend(Former::link('Browse')->class('popup_selector ')->dataInputid('file'));
    
    opened by biwerr 0
Releases(4.7.0)
  • 4.7.0(Feb 17, 2022)

  • 5.0.0-rc.1(Jun 2, 2021)

    Added

    • Add Bootstrap 5 floating labels via the floatingLabel() method for <input>, <select> and <textarea> tags

      NOTE: You need to use floating label elements with a vertical_open Former instance!

      Usage with Laravel:

      {!! Former::vertical_open() !!}
          {!!
              Former::text('test-floating-label-ok')
                  ->placeholder('dummy placeholder')
                  ->floatingLabel()
          !!}
          {!!
              Former::select('users-floating-label')
                  ->options(['User One', 'User Two', 'User Three'])
                  ->placeholder('Select placeholder')
                  ->floatingLabel()
          !!}
          {!!
              Former::textarea('textarea-floating-label')
                  ->floatingLabel()
                  ->placeholder('dummy placeholder')
          !!}
      {!! Former::close() !!}
      
      {!! Former::vertical_open() !!}
          <div class="row">
              <div class="col">
                  {!!
                      Former::text('test-floating-label-one')
                          ->placeholder('dummy placeholder')
                          ->floatingLabel()
                  !!}
              </div>
              <div class="col">
                  {!!
                      Former::text('test-floating-label-two')
                          ->placeholder('dummy placeholder')
                          ->floatingLabel()
                  !!}
              </div>
          </div>
      {!! Former::close() !!}
      
    • Add the switch markup which is a custom checkbox for Bootstrap 5

      Some use cases with Laravel:

      {!!
          Former::switch('valid_switch_ok')
              ->text('Valid switch OK')
      !!}
      
      {!!
          Former::switches('valid_inline_switches_ok')
              ->switches('first', 'second', 'third', 'fourth')
              ->inline()
      !!}
      
    • Add removeGroupClass() and removeLabelClass() methods

      Usage with Laravel:

      {!!
          Former::text('test')
              ->removeGroupClass('row')
              ->removeLabelClass('foo')
      !!}
      

      WARNING: There is a bug in the HTMLObject package! See my pull request for more info: https://github.com/Anahkiasen/html-object/pull/34

    Source code(tar.gz)
    Source code(zip)
  • 5.0.0-alpha(Jan 21, 2021)

    Added

    • Add CSS class to the label of a group, with the addLabelClass() method (#604)

    Changed

    • Better Bootstrap 4 support
    • Breaking change: Escape HTML value of plaintext field by default (#605) You can disable this new behavior with the escape_plaintext_value former config option set to false. In your former config file config/former.php, you can enable or disable this feature:
    <?php
    
    return [
        //...
    
        // Whether Former should escape HTML tags of 'plaintext' fields
        // Enabled by default
        //
        // Instead of disabled this option,
        // you should use the 'HtmlString' class:
        //  Former::plaintext('text')
        //      ->forceValue(
        //          new Illuminate\Support\HtmlString('<b>HTML data</b>')
        //      )
        'escape_plaintext_value' => true,
    
        //...
    ];
    
    Source code(tar.gz)
    Source code(zip)
  • 4.6.0(Nov 30, 2020)

    • Drop support for Laravel < 5.1.2 (if you need support for earlier Laravel version you can continue to use Former 4.4.x and lower)
    • Add support for PHP 8.0
    Source code(tar.gz)
    Source code(zip)
  • 4.5.0(Sep 23, 2020)

    • Drop support for PHP 7.1 and lower (if you need support for PHP 7.1 or lower use Former version 4.4.x or lower)
    • Add support for Laravel 8
    Source code(tar.gz)
    Source code(zip)
  • 4.4.0(Mar 4, 2020)

  • 4.3.2(Dec 10, 2019)

  • 4.3.1(Dec 9, 2019)

  • 4.3.0(Sep 4, 2019)

  • 4.2.2(Aug 26, 2019)

  • 4.2.1(Aug 20, 2019)

  • 4.2.0(Jan 31, 2019)

  • 4.1.11(Jan 30, 2019)

  • 4.1.10(Oct 25, 2018)

  • 4.1.9(Oct 25, 2018)

  • 4.1.8(Oct 24, 2018)

  • 4.1.7(Jul 24, 2018)

  • 4.1.6(Jan 2, 2018)

  • 4.1.5(Nov 27, 2017)

  • 4.1.4(Nov 27, 2017)

  • 4.1.3(Nov 22, 2017)

  • 4.1.1(May 30, 2017)

    Fixes for regex rules with commas, pipes per #544 -- thanks @KuenzelIT and @tortuetorche!

    Also, I've done some cleanup of our issue queue, PRs, docs, and simplified our development structure.

    Former will no longer use a development branch, and the 4.0 branch is now deprecated and will be removed after it appears safe to do so.

    All development should now take place on the master branch. Laravel 4.0 support is now bug-fix-only mode using the 3.x.x tags. -- new features will target only laravel 5.

    Happy Former'ing!

    Source code(tar.gz)
    Source code(zip)
  • 4.0.6(Jul 28, 2016)

  • 3.5.12(Jul 28, 2016)

  • 4.0.5(Apr 18, 2016)

  • 3.5.11(Apr 18, 2016)

  • 4.0.4(Apr 8, 2016)

Laravel Form builder for version 5+!

Laravel 5 form builder Form builder for Laravel 5 inspired by Symfony's form builder. With help of Laravels FormBuilder class creates forms that can b

Kristijan Husak 1.7k Dec 31, 2022
Reactive Form Builder for Vue.js with Laravel Support

Dynamic Form Builder for Laravel with Vue.js Create even the most complex forms with ease, using two-sided validation, eloquent, nested elements, cond

Laraform 340 Dec 31, 2022
A demo of how to use filament/forms to build a user-facing Form Builder which stores fields in JSON.

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Dan Harrin 41 Dec 24, 2022
Composer package which adds support for HTML5 elements using Laravels Form interface (e.g. Form::date())

Laravel HTML 5 Inputs Composer package which adds support for HTML5 elements by extending Laravel's Form interface (e.g. Form::date()) Adds support fo

Small Dog Studios 11 Oct 13, 2020
HydePHP - Elegant and Powerful Static App Builder

HydePHP - Elegant and Powerful Static App Builder Make static websites, blogs, and documentation pages with the tools you already know and love. About

HydePHP 31 Dec 29, 2022
A toolkit for developing universal web interfaces with support for multiple CSS frameworks.

PHP UI Kit A toolkit for developing universal web interfaces with support for multiple CSS frameworks. Documentation Use cases One of the use cases is

Róbert Kelčák 6 Nov 8, 2022
A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)

Laravel MongoDB This package adds functionalities to the Eloquent model and Query builder for MongoDB, using the original Laravel API. This library ex

Jens Segers 6.3k Jan 7, 2023
A Laravel Admin Starter project with Page Builder, Roles, Impersonation, Analytics, Blog, News, Banners, FAQ, Testimonials and more

Laravel CMS Starter Project A Laravel CMS Starter project with AdminLTE theme and core features. Preview project here User: [email protected]

Ben-Piet O'Callaghan 306 Nov 28, 2022
A DynamoDB based Eloquent model and Query builder for Laravel.

Laravel DynamoDB A DynamoDB based Eloquent model and Query builder for Laravel. You can find an example implementation in kitar/simplechat. Motivation

Satoshi Kita 146 Jan 2, 2023
Boilerplate code for protecting a form with proof of work. Uses javascript in the browser to generate the hashcash and PHP on the server to generate the puzzle and validate the proof of work.

Boilerplate code for protecting a form with proof of work. Uses javascript in the browser to generate the hashcash and PHP on the server to generate the puzzle and validate the proof of work.

Jameson Lopp 28 Dec 19, 2022
Razorpay payment gateway integration in laravel with submit form and storing details in payment table.

Integrating razorpay payment gateway in laravel with submit form and storing payment details in payment table. How to settup the project in your local

Mohammed-Thamnees 3 Apr 15, 2021
Laravel Livewire form component with declarative Bootstrap 5 fields and buttons.

Laravel Livewire Forms Laravel Livewire form component with declarative Bootstrap 5 fields and buttons. Requirements Bootstrap 5 Installation composer

null 49 Oct 29, 2022
Rapid form generation with Bootstrap 3 and Laravel.

Important: This package is not actively maintained. For bug fixes and new features, please fork. BootForms BootForms builds on top of my more general

Adam Wathan 423 Jun 14, 2022
Generate and autoload custom Helpers, Builder Scope, Service class, Trait

laravel-make-extender Generate and autoload custom helpers, It can generate multilevel helpers in the context of the directory. Generate Service class

Limewell 30 Dec 24, 2022
this is cv-builder project in php and ajax

download the project make a database has name cv_builder extract the project in xampp/htdocs/ open the project localhost/cv_builder/index.php or use t

Hilal ahmad 6 Jun 21, 2022
A WPDB wrapper and query builder library.

DB A WPDB wrapper and query builder library. Installation It's recommended that you install DB as a project dependency via Composer: composer require

StellarWP 35 Dec 15, 2022
Provides a Eloquent query builder for Laravel or Lumen

This package provides an advanced filter for Laravel or Lumen model based on incoming requets.

M.Fouladgar 484 Jan 4, 2023
Laravel Mysql Spatial Builder Extension

magutti-spatial V2 Laravel Builder Mysql Spatial Extension Laravel Builder extensions to calculate distances between two Spatial points using Mysql na

Marco Asperti 4 Oct 2, 2022
A TWBS menu builder for Laravel

Laravel Menu Builder A menu builder for Laravel 4-5 using Bootstrap's markup. Документация на Русском Note that this package is shipped with no styles

Alexander Kalnoy 24 Nov 29, 2022