Download the PHP package jonob/formly without Composer

On this page you can find all versions of the php package jonob/formly. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package formly

Laravel Form Package

Forms support in Laravel, with Twitter Bootstrap styling. All form inputs use Laravel's form helpers to create the actual html. Some added goodies like setting form defaults, repopulating forms after failed validation and showing failed validation errors.

There is a 5 minute video overview of using Formly. Although this was originally done for Laravel 3, the concepts remain identical.

Installation

Composer

Add "jonob/formly": "dev-master", to the require section of your composer.json:

Now run composer update.

Laravel

Add the following code to the providers section of the app/config/app.php file:

Add the following code to the aliases section of the app/config/app.php file:

Usage

Routes and Controllers

To start off with, you create a new form object in your route/controller. This can be done with a static method as follows:

Or you can instantiate it like so:

You then pass the form object to your view as follows. This means that that formly will be available in your view with the $form variable.

Forms

In generaly, Formly follows Laravel's default form helpers in terms of the method names and function parameters. There are two exceptions. Firstly, all methods are called non-statically and secondly the second parameter in Formly is the input's label. For example:

Because we specify the label name in the method, there is no need to have a separate label field on your form - Formly will generate it for you automatically.

When it comes to opening your forms, then you just call the open method as follows. Notice that its not necessary to specify the action - by default Formly will POST to the current URL. You can of course override this if you wish.

Using this method has the added benefit that a hidden CSRF token will be automatically inserted for you. You can override this if you want.

Setting form values

Using formly to set default values

If you are populating your form from existing data (for example, if you are editng a record from your database), then its not necessary to do this for each field. Let Formly do all the work for you as follows:

In order for this to work, the field names for your forms MUST have the same names as your database fields. If they are not the same, then Formly has no idea how to connect the two together.

You can populate fields manually if you wish:

Setting default values inline for each input

Alternatively, you can also set default values for individual form fields in the actual form. Values set in this way will override defaults set via the method above.

Setting default via $_POST

Well, this is not something that you do - Formly does it for you automatically. If, for example, you try save a form and validation fails, then Formly will automatically repopulate each input with the posted data.

Cascade

Based on the above, its evident that there are 3 methods of populating your forms. The order of precedence is as follows:

Validation

Formly automatically hooks up to Laravel's validation library with very little effort. Lets look at a full example.

Notice that if validation fails, then its necessary to redirect with the errors and the input. By doing this, we achieve two things:

Note that you do not need to do anything special to your form - simply by returning withErrors() and withInput(), Formly knows what to do

Submit buttons

Creating a submit button is easy:

By default, Formly will add in the Twitter Bootstrap 'btn' class. You can override this in the third parameter if you want:

There are also some shortcuts for all the Twitter Bootstrap button styles:

Formly Options

There are a couple of options that allow you to customise how Formly works. You can override these when the class is instantiated or through the setOption() method. Note that setOption() can be used to set many options at once, or a single option.

formClass (default: form_horizontal)

By default, forms are styled using form-horizontal, but you can choose any of Bootstrap's other styles, such as form-vertical, form-inline, form-search

autoToken (default: true)

Automatically adds a csrf token to the form_open method

nameAsId (default: true)

Automatically creates an id for each field based on the field name

idPrefix (default: field_)

If name_as_id is enabled, then this string will be prefixed to the id attribute

requiredLabel (default: .req)

Say you want to identify a label as being a required field on your form. Using formly, you can just append this string to the label parameter, and Formly will automatically use the required_prefix, required_suffix and required_class

requiredPrefix (default:'')

If the required_label has been set, then the text from this variable will be prefixed to your label

requiredSuffix (default:' *')

If the required_label has been set, then the text from this variable will be added to the end of your label

requiredClass (default: 'label-required')

If the required_label has been set, then this class will be added to the label's attribute. You want the label to be bold, for example, which you can then style in your css

controlGroupError (default: 'error')

Display a class for the control group if an input field fails validation

displayInlineErrors (default: false)

If the field has failed validation, then inline errors will be shown


All versions of formly with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jonob/formly contains the following files

Loading the files please wait ....