Download the PHP package gregwar/formidable without Composer

On this page you can find all versions of the php package gregwar/formidable. 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 formidable

Formidable

PHP 7 PHP 7.1 PHP 7.2 Build status paypal

Formidable is a PHP library to handle forms. It parses an HTML form and allows you to manipulate it from your PHP code, and then render it.

How does it work?

Step 1: Download & install Formidable

Via composer:

Or with a clone of the repository:

Or downloading it:

Step 2: Write your form in HTML

First, you have to write your code in HTML, for instance:

Step 3: Give it to Formidable

In your PHP code, give your form to Formidable:

Simple, right?

Step 4: Enjoy the magic

You can then use the Formidable API to play with your form:

You can also try to change your form and add constraint directly in the HTML code:

This will force the text to be at least 10 characters long when the server-side constraints will be checked.

Want a CAPTCHA to secure your form?

This will generate an image and an input field on the client-side, and use session on the server-side to check that the code is correct.

Note that this will use the dependency with Gregwar/Captcha library (you will have to install dependencies using composer).

Types

The following input types are supported:

Attributes

Note that some attributes are not HTML-valid, like maxlength:

It will not be rendered in the HTML form, but will be used to check integrity.

Here is the list of available attributes:

API

You can call these method on your $form object:

CSRF protection

An additional CSRF token is automatically inserted in the form and checked when it's submitted. Thus, all your forms will be secured.

The presence and validity of CSRF token is used to check that a form was posted when calling posted method (it's used internally in handle)

If you specify the name attribute in the form, the CSRF token will be different for this specific form, this will allow Formidable to make the difference of which form is submitted if there is multiple form on the same page.

Languages

The language for the errors can be set with setLanguage():

Check that your language is supported in the Language directory, don't hesitate to participate!

Source

You can use the sourcing system to populate dynamically a select, a multiradio or a multicheckbox:

Then populate it with source:

This will be rendered by some checkboxes.

You can do it this way with select:

And then source it with the same method

Creating form from string

You can create form from a file or from a string, this will be detected automatically:

Mapping

You can also use mapping attribute to populate your form or to get back the form data in an array or in an object, for instance:

Note that the mapping uses the Symfony PropertyAccessor, you can then use accessor as in the example above to populate properties.

You can use:

Creating multiple sub-forms

You can add multiple sub-forms to a page using the <multiple> tag:

With this, the <multiple> can be used exactly like a field, but it will contains an array of elements.

Some JS will be injected in the page and allow you to add/remove some elements.

You can use min-entries and max-entries constraint to set limits on the number of entries in a multiple.

If you specify the same value for min-entries and max-entries, or specify a value for entries (which is actually an alias to do it), the number ofr inputs will be fixed and no javascript will be required.

Adding dynamic data into the form

In some case, you'll want to add custom data into the form, there is two way to do this.

First way: using the placeholders

The {{ something }} syntax allow you to simply inject data from the code, like this:

In the example above, the {{ name }} will be rendered as Bob.

Note that placeholders may be used anyway excepted in the <form> and input tags:

Second way: using PHP form

You can also write your form using PHP, like a template, for instance:

And then instanciate your form passing the template variables as a second argument:

The $label will be interpreted using PHP.

Caching

For performances reasons, you may want to cache the parsed forms.

To do this, simply pass true as the third argument of the constructor:

This will use the Gregwar/Cache system, you will need to get the composer dependencies of this repository or install it manually. By default, cache files will be wrote in the cache directory from where the script is run.

Try to run the performances.php script in the examples/ directory, this will give you an example of performance gain with cache.

You can also pass an instance of Gregwar\Cache\Cache as the third parameter, which will allow you to set the cache directory.

License

Gregwar\Formidable is under MIT License, have a look at the LICENSE file for more information.

History

V2.0.0 End support for PHP <5.6

V2.1.0 Remove hard dependency on Captcha library


All versions of formidable with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0
gregwar/cache Version ~1.0.9
symfony/property-access Version ~2.8.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 gregwar/formidable contains the following files

Loading the files please wait ....