PHPackages                             teknicode/bootstrap-forms - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. teknicode/bootstrap-forms

ActiveLibrary[Templating &amp; Views](/categories/templating)

teknicode/bootstrap-forms
=========================

PHP Class to generate an HTML form with Bootstrap 4 styling. A built in form capture class can send the form via Email, SMS or MySQLi. Includes Google ReCaptcha.

2.6.0(7y ago)060MITPHPPHP &gt;=5.5

Since Apr 7Pushed 7y agoCompare

[ Source](https://github.com/teknicode/bootstrap-forms)[ Packagist](https://packagist.org/packages/teknicode/bootstrap-forms)[ RSS](/packages/teknicode-bootstrap-forms/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (13)Used By (0)

Simple Form Generator
---------------------

[](#simple-form-generator)

This simple class allows fast generation of html forms with Bootstrap styling.

### Installation

[](#installation)

```
composer require teknicode/bootstrap-forms

```

### Usage

[](#usage)

```
require("src/Form.php");
use Teknicode\Form\Form;

$form = new Form();

```

Now you're ready to generate a form. Open the form and pass in an array containing attributes to be included in the form tag. If you don't provide an action attribute the form will submit to its current url.

```
$form->open([
    "id" => "my_form",
    "action" => "my url"
]);

```

Outputs ``

Add an input to the form. The int in `input(1)` defines the width of the input according to Bootstraps Grid system. For example `input(6)` will set the input width to `col-md-6`.

```
$form->input(1)->set([
    "name"=>"my_first_input",
    "type"=>"text",
    "value" => "The current value of the input",
    "label" => "My First Input"
]);

```

Outputs `` wrapped with a label.

To add a select.

```
$form->select(2)->set([
    "name"=>"my_select",
    "label"=>"My Select",
    "value" => "option3",
    "options" => [
        "First Group Test"=>"--group--",
        "Option 1" => [
            "value" => "option1",
            "custom-option-attribute" => "attribute value"
        ],
        "Option 2" => "option2",
        "Second Group Test"=>"--group--",
        "Option 3" => "option3",
        "Option 4" => "option4"
    ]
]);

```

Radio button also require an array of options.

```
$form->input(1)->set([
    "name"=>"my_radio",
    "type" => "radio",
    "value" => "value2",
    "label" => "This is a radio button",
    "options" => [
        "option 1" => "value1",
        "option 2" => "value2"
    ]
]);

```

The value attribute will pre select the option from those provided in the options array.

Add html or a spacer.

```
$form->html(
    6, //grid width
    'My Content'
);

```

Add Google ReCaptcha. You will need to create an api key at

```
$form->recaptcha("your api public key");

```

NOTE: You must include the following javascript in your page. ``

Add a button.

```
$form->button(1)->set([
    "text"=>"My Button",
    "class"=>"btn-lg btn-primary"
]);

```

Now simply output the form.

`echo $form->compile()`

Catch and Process Posted Data
-----------------------------

[](#catch-and-process-posted-data)

Initialize the class object

```
use Teknicode\Form\Process;
$process = new Process("mail" or "sms"); //mail is default

```

Provide settings using the set method as show below:

```
$process->set("recipient","email@address.co.uk" /*string or array of strings*/ );
$process->set("from",["address"=>"sender@address.co.uk","name"=>"Sender Name"]);

```

Setup SMTP credentials - skip this to send with mail()

```
$process->set("smtp",[
  "Host"=>"mailerserver.url.com",
  "Username"=>"email@username",
  "Password"=>"AccountPassword",
  "SSL"=>"tls",
  "Port"=>587
]);

```

If you are using SMS, you must provide the following AWS credentials:

```
$process->set("aws", [
   "aws_access_key_id" => "",
   "aws_secret_access_key" => "",
   "default_region" => "eu-west-1",
   "sms_sender_id" => ""
]);

//you would then provide a mobile number in recipient including the country code:
$process->set("recipient","+4407123456789");

```

If you are using MySQLi, you must provide the following credentials:

```
$process->set("mysqli", [
   "host" => "",
   "username" => "",
   "password" => "",
   "database" => "",
   "table" => ""
]);

//you would then provide the values to be set:
$process->set("values",[
  "field name" => "value"
]]);

//to update an existing entry provide the id
$process->set("id",INT);

```

Check Google ReCaptcha (optional)

```
$process->recaptcha("your api private key");
//used to check the recaptcha response

```

Now all thats needed is to catch the post!

```
$send = $process->catch();

if( $send['status']=="failed" ){
  //do something with the error message
  echo $send['error'];

  //in the event of an error the post values are passed back //to repopulate the form
  $send['data'] contains $_POST
}

```

The catch method will parse the posted data and create a simple clean email containing the name of the input and value set.

#### List of available settings

[](#list-of-available-settings)

Email

```
$process->set("recipient",STRING | ARRAY OF STRINGS);

$process->set("from",["address"=>STRING,"name"=>STRING]);

$process->set("replyto",STRING);

$process->set("subject",STRING);

process->set("smtp",[
  "Host"=>STRING,
  "Username"=>STRING,
  "Password"=>STRING,
  "SSL"=>STRING,
  "Port"=>INT
]);

```

SMS

```
$process->set("recipient","+4407123456789");

$process->set("aws", [
   "aws_access_key_id" => "",
   "aws_secret_access_key" => "",
   "default_region" => "eu-west-1",
   "sms_sender_id" => ""
]);

```

MySQLi

```
$process->set("id",INT); //optional for update instead of insert

$process->set("mysqli", [
   "host" => "",
   "username" => "",
   "password" => "",
   "database" => "",
   "table" => ""
]);

$process->set("values",[
  "field name" => "value"
]);

```

### License

[](#license)

Copyright 2018 Teknicode

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~17 days

Recently: every ~6 days

Total

12

Last Release

2770d ago

Major Versions

1.0.0 → 2.0.02018-04-09

### Community

Maintainers

![](https://www.gravatar.com/avatar/6b3da0819724a3af76ae3145614d7e680ef862dd1561e0ae6eb9d482eaaed848?d=identicon)[teknicode](/maintainers/teknicode)

---

Top Contributors

[![teknicode](https://avatars.githubusercontent.com/u/37957290?v=4)](https://github.com/teknicode "teknicode (29 commits)")

---

Tags

htmlbootstrapform

### Embed Badge

![Health badge](/badges/teknicode-bootstrap-forms/health.svg)

```
[![Health](https://phpackages.com/badges/teknicode-bootstrap-forms/health.svg)](https://phpackages.com/packages/teknicode-bootstrap-forms)
```

###  Alternatives

[tomaj/nette-bootstrap-form

Nette bootstrap form renderer

28440.4k6](/packages/tomaj-nette-bootstrap-form)[tomjamon/laravel-custom-html

Custom HTML generator for Laravel (Based on LaravelCollective HTML)

1018.6k](/packages/tomjamon-laravel-custom-html)[vluzrmos/collective-html

LaravelCollective Html and Form builder for Lumen.

2523.9k](/packages/vluzrmos-collective-html)[zfbase/zend1-bootstrap3

Twitter Bootstrap v.3 Forms for Zend Framework v.1

1455.7k2](/packages/zfbase-zend1-bootstrap3)[mopa/bootstrap-sandbox-bundle

Seperate live docs from code

256.8k](/packages/mopa-bootstrap-sandbox-bundle)[cornford/bootstrapper

An easy way to intergrate Twitter Bootstrap with Laravel.

232.7k](/packages/cornford-bootstrapper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
