All Projects → formr → Formr

formr / Formr

Licence: gpl-2.0
Create and Validate PHP Forms in Seconds.

Projects that are alternatives of or similar to Formr

Bootstrap Validate
A simple Form Validation Library for Bootstrap 3 and Bootstrap 4 not depending on jQuery.
Stars: ✭ 112 (-31.29%)
Mutual labels:  validation, form-validation, bootstrap, bootstrap4
Usetheform
React library for composing declarative forms, manage their state, handling their validation and much more.
Stars: ✭ 40 (-75.46%)
Mutual labels:  validation, form-validation, form-builder
React Hook Form
📋 React Hooks for form state management and validation (Web + React Native)
Stars: ✭ 24,831 (+15133.74%)
Mutual labels:  validation, form-validation, form-builder
Blazorise
Blazorise is a component library built on top of Blazor with support for CSS frameworks like Bootstrap, Bulma, AntDesign, and Material.
Stars: ✭ 2,103 (+1190.18%)
Mutual labels:  bootstrap, bulma, bootstrap4
Tabler React
React components and demo for the Tabler UI theme.
Stars: ✭ 1,830 (+1022.7%)
Mutual labels:  bootstrap, bootstrap4
Shards Ui
🎨Shards is a beautiful & modern Bootstrap 4 UI kit packed with extra templates and components.
Stars: ✭ 1,718 (+953.99%)
Mutual labels:  bootstrap, bootstrap4
Startbootstrap Agency
Start Bootstrap is an open source library of free Bootstrap themes and templates. All of the free themes and templates on Start Bootstrap are released under the MIT license, which means you can use them for any purpose, even for commercial projects.
Stars: ✭ 1,810 (+1010.43%)
Mutual labels:  bootstrap, bootstrap4
Startbootstrap Simple Sidebar
Start Bootstrap is an open source library of free Bootstrap templates and themes. All of the free templates and themes on Start Bootstrap are released under the MIT license, which means you can use them for any purpose, even for commercial projects.
Stars: ✭ 1,833 (+1024.54%)
Mutual labels:  bootstrap, bootstrap4
Cakephp3 Bootstrap Helpers
CakePHP 3.x Helpers for Bootstrap 3 and 4.
Stars: ✭ 134 (-17.79%)
Mutual labels:  bootstrap, bootstrap4
Bootstrap Blocks Wordpress Plugin
Bootstrap Gutenberg Blocks for WordPress
Stars: ✭ 143 (-12.27%)
Mutual labels:  bootstrap, bootstrap4
Neoform
✅ React form state management and validation
Stars: ✭ 162 (-0.61%)
Mutual labels:  validation, form-validation
Majesticadmin Free Bootstrap Admin Template
Simple Bootstrap 4 Dashboard template.
Stars: ✭ 160 (-1.84%)
Mutual labels:  bootstrap, bootstrap4
Bootstrap Table
An extended table to integration with some of the most widely used CSS frameworks. (Supports Bootstrap, Semantic UI, Bulma, Material Design, Foundation, Vue.js)
Stars: ✭ 11,068 (+6690.18%)
Mutual labels:  bootstrap, bulma
Bootstrap4
Repository for my tutorial course: Bootstrap 4 Essential Training on LinkedIn Learning and Lynda.com.
Stars: ✭ 142 (-12.88%)
Mutual labels:  bootstrap, bootstrap4
Coreui Free Bootstrap Admin Template
CoreUI is free bootstrap admin template
Stars: ✭ 11,038 (+6671.78%)
Mutual labels:  bootstrap, bootstrap4
Startbootstrap Clean Blog Jekyll
Start Bootstrap is an open source library of free Bootstrap templates and themes. All of the free templates and themes on Start Bootstrap are released under the MIT license, which means you can use them for any purpose, even for commercial projects.
Stars: ✭ 1,837 (+1026.99%)
Mutual labels:  bootstrap, bootstrap4
Formhelper
ASP.NET Core - Transform server-side validations to client-side without writing any javascript code. (Compatible with Fluent Validation)
Stars: ✭ 155 (-4.91%)
Mutual labels:  validation, form-validation
Sage
WordPress starter theme with a modern development workflow
Stars: ✭ 11,531 (+6974.23%)
Mutual labels:  bootstrap, bootstrap4
Architectui Html Theme Free
ArchitectUI Dashboard Free is lightweight and comes packed with the minimal set of components to get you started. If you have a simple application, it’s the perfect solution for you. It’s built on top of Bootstrap 4 and features a scalable architecture just like it’s wiser, older sibling – ArchitectUI HTML Pro theme.
Stars: ✭ 155 (-4.91%)
Mutual labels:  bootstrap, bootstrap4
Form Validation.js
The most customizable validation framework for JavaScript.
Stars: ✭ 127 (-22.09%)
Mutual labels:  validation, form-validation

Formr

Formr is a PHP micro-framework which installs easily and helps you build, layout and validate forms quickly, painlessly, and without all the complicated, messy overhead.

Find docs here: http://formr.github.io

If you find Formr useful, please consider starring the project and/or making a donation. Thank you!

Features

  • Create complex forms with server-side processing and validation in seconds
  • Built-in support for Bootstrap and Bulma
  • Built-in POST validation rules, including validating email, comparisons, slugging and hashing
  • Instantly make one field required, all fields required, or all but one field required
  • Create and validate radio groups and checkbox arrays in seconds
  • Upload images: resize, rename, and create thumbnails
  • Extensible: easily create and save your own field element wrappers
  • Extensible: easily create and save your own dropdown menus
  • Extensible: easily create and save your own form & validation sets
  • Send plain text and HTML emails
  • Generate CSRF tokens and set the expiration time
  • Object-oriented; supports multiple forms per page
  • Little helpers to assist in building, layout, testing and debugging
  • And a ton of other cool stuff!

Installation

Composer

Run the following command to install Formr with Composer

composer require formr/formr

Then include the autoload.php file and create a new form object.

require_once 'vendor/autoload.php';
$form = new Formr\Formr();

Download

Download the .zip file and place the Formr folder in your project, then include the Formr class and create a new form object.

require_once 'Formr/class.formr.php';
$form = new Formr\Formr();

Bootstrap & Bulma Ready

Bootstrap and Bulma form classes are ready to go! Just tell Formr you want to use Bootstrap or Bulma when creating a new form and Formr will take care of the rest.

$form = new Formr\Formr('bootstrap');
$form = new Formr\Formr('bulma');

Basic Example

Simply enter your form labels as a comma delimited string and Formr will build the form, complete with opening and closing tags, a submit button, and email validation - plus all values retained upon POST. Easy!

$form = new Formr\Formr('bootstrap');
$form->create_form('Name, Email, Comments|textarea');

Produces the following HTML

<form action="/index.php" method="post" accept-charset="utf-8">

    <div id="_name" class="form-group">
        <label class="control-label" for="name">
            Name
        </label>
        <input type="text" name="name" id="name" class="form-control">
    </div>

    <div id="_email" class="form-group">
        <label class="control-label" for="email">
            Email
        </label>
        <input type="email" name="email" id="email" class="form-control">
    </div>

    <div id="_comments" class="form-group">
        <label class="control-label" for="comments">
            Comments
        </label>
        <textarea name="comments" id="comments" class="form-control"></textarea>
    </div>

    <div id="_button" class="form-group">
        <label class="sr-only" for="button"></label>
        <button type="submit" name="button" id="button" class="btn btn-primary">Submit</button>
    </div>

</form>

Basic Example with More Control

Using the create() method tells Formr you want control over adding the form tags and submit button yourself. Otherwise it's the same as the Basic Example above.

$form = new Formr\Formr('bootstrap');
$form->form_open();
$form->create('First name, Last name, Email address, Age|number, Comments|textarea');
$form->submit_button();
$form->form_close();

Produces the following HTML

<form action="/index.php" method="post" accept-charset="utf-8">
    <div id="_first_name" class="form-group">
        <label class="control-label" for="first_name">
            First name
        </label>
        <input type="text" name="first_name" id="first_name" class="form-control">
    </div>
    <div id="_last_name" class="form-group">
        <label class="control-label" for="last_name">
            Last name
        </label>
        <input type="text" name="last_name" id="last_name" class="form-control">
    </div>
    <div id="_email_address" class="form-group">
        <label class="control-label" for="email_address">
            Email address
        </label>
        <input type="email" name="email_address" id="email_address" class="form-control">
    </div>
    <div id="_age" class="form-group">
        <label class="control-label" for="age">
            Age
        </label>
        <input type="number" name="age" id="age" class="form-control">
    </div>
    <div id="_comments" class="form-group">
        <label class="control-label" for="comments">
            Comments
        </label>
        <textarea name="comments" id="comments" class="form-control"></textarea>
    </div>
    <div id="_submit" class="form-group">
        <label class="sr-only" for="submit"></label>
        <button type="submit" name="submit" id="submit" class="btn btn-primary">Submit</button>
    </div>
</form>

Pre-Built Forms

Formr has several common forms already baked in, and it's really easy to create and save your own.

$form = new Formr\Formr();
$form->fastform('contact');

Produces the following HTML

<form action="/index.php" method="post" accept-charset="utf-8">
    <fieldset>
        <label for="fname">
            First name:
        </label>
        <input type="text" name="fname" id="fname" class="input">

        <label for="lname">
            Last name:
        </label>
        <input type="text" name="lname" id="lname" class="input">

        <label for="email">
            Email:
        </label>
        <input type="email" name="email" id="email" class="input">

        <label for="comments">
            Comments:
        </label>
        <textarea name="comments" id="comments" class="input" ></textarea>

        <input type="submit" name="submit" value="Submit" id="submit">
    </fieldset>
</form>

Build Forms With Arrays

$data = [
    'text' => 'name, Name:',
    'email' => 'email, Email:',
    'checkbox' => 'agree, I Agree',
];

$form = new Formr\Formr('bootstrap');
$form->fastform($data);

Produces the following HTML

<form action="/index.php" method="post" accept-charset="utf-8">
    <fieldset>
        <div id="_name" class="form-group">
            <label class="control-label" for="name">
                Name:
            </label>
            <input type="text" name="name" class="form-control" id="name">
        </div>

        <div id="_email" class="form-group">
            <label class="control-label" for="email">
                Email:
            </label>
            <input type="email" name="email" class="form-control" id="email">
        </div>

        <div id="_agree" class="checkbox">
            <label for="agree">
                <input type="checkbox" name="agree" value="agree" id="agree"> I Agree
            </label>
        </div>

        <div id="_submit" class="form-group">
            <label class="sr-only" for="submit"></label>
            <input type="submit" name="submit" value="Submit" id="submit" class="btn">
        </div>
    </fieldset>
</form>

Build Forms in HTML

You have full control over how you build your forms...

<div class="my-wrapper-class">
    <?php $form->text('name', 'Name'); ?>
</div>

<div class="my-wrapper-class">
    <?php $form->email('email', 'Email address', '[email protected]', 'emailID', 'placeholder="[email protected]"'); ?>
</div>

<div class="my-wrapper-class">
    <input type="text" name="address" value="<?php $form->value('address') ?>">
</div>

Produces the following HTML

<div class="my-wrapper-class">
    <label for="name">
        Name
    </label>
    <input type="text" name="name" id="name">
</div>

<div class="my-wrapper-class">
    <label for="emailID">
        Email address
    </label>
    <input type="email" name="email" id="emailID" value="[email protected]" placeholder="[email protected]">
</div>

Retrieving POST Values

It's super easy to retrieve your $_POST values and assign them to variables!

$name = $form->post('name');
$email = $form->post('email');

Validation

Formr can easly process and validate your forms

Like the create() method, we can pass a list of our form labels to the validate() method, which will get the $_POST values of our form fields and put them into an array. If your field name is email, a valid_email validation rule will be applied automatically!

Basic usage

$form->validate('Name, Email, Comments');

Let's make sure the form was submitted, then we'll validate and get the value of our email field from the array.

if($form->submitted()) {
    $data = $form->validate('Name, Email, Comments');
    $email = $data['email'];
}

Adding Rules

Let's make sure Name is a minimum of 2 characters and a maximum of 30 by adding our validation rules wrapped in parentheses.

$form->validate('Name(min[2]|max[30]), Email, Comments');

Fine-Tune Your Validation

Of course you can get more in-depth with your validation, and even add custom error messaging! The following is a basic example, however Formr's validation methods are quite powerful and include, among other things, comparing values between fields and hashing using bcrypt()

Let's get the value of our email field using the post() method.

$email = $form->post('email');

Now let's make sure it's a valid email address by entering the valid_email validation rule in the third parameter. If there's an error, the text entered into the second parameter will notify the user to correct the Email field.

$email = $form->post('email','Email','valid_email');

We can take that a step further and enter a full custom error message in the second parameter to make our forms even more user-friendly.

$email = $form->post('email','Email|Please enter a valid email address','valid_email');

Full Example

<?php
// include the Formr class
require_once 'Formr/class.formr.php';

// create our form object and use Bootstrap 4 as our form wrapper
$form = new Formr\Formr('bootstrap');

// make all fields required
$form->required = '*';

// check if the form has been submitted
if($form->submitted())
{
    // make sure our Message field has at least 10 characters
    $form->validate('Message(min_length[10])');

    // let's email the form
    $to = '[email protected]';
    $from = '[email protected]';
    $subject = 'Contact Form Submission';

    // this processes our form, cleans the input, and formats it into an HTML email
    if($form->send_email($to, $subject, 'POST', $from, 'HTML'))
    {
        // email sent; print a thank you message
        $form->success_message('Thank you for filling out our form!');
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>Formr</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" crossorigin="anonymous">
</head>
<body>
    <div class="container">
        <?php
            // print messages, formatted using Bootstrap alerts
            $form->messages();

            // create the form
            $form->create_form('First name, Last name, Email address, Message|textarea');
        ?>
    </div>
</body>
</html>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].