PHPackages                             mos/cform - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. mos/cform

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mos/cform
=========

PHP classes for HTML forms handling

v1.9.8(9y ago)52.0k2[8 issues](https://github.com/mosbth/cform/issues)7MITPHPPHP &gt;=5.4

Since Apr 15Pushed 9y ago2 watchersCompare

[ Source](https://github.com/mosbth/cform)[ Packagist](https://packagist.org/packages/mos/cform)[ Docs](http://dbwebb.se/)[ RSS](/packages/mos-cform/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (11)Used By (7)

CForm a PHP class for creating, rendering and validating HTML forms.
====================================================================

[](#cform-a-php-class-for-creating-rendering-and-validating-html-forms)

There is an article written on CForm, in swedish though.

-

By Mikael Roos ()

License
-------

[](#license)

This software has dual license, MIT LICENSE and GPL VERSION 3.

Form elements
-------------

[](#form-elements)

The class `CForm` uses `CFormElements`.

The following form elements are supported:

```
class CFormElementText extends CFormElement {
class CFormElementTextarea extends CFormElement {
class CFormElementHidden extends CFormElement {
class CFormElementPassword extends CFormElement {
class CFormElementCheckbox extends CFormElement {
class CFormElementCheckboxMultiple extends CFormElement {
class CFormElementSubmit extends CFormElement {

```

Validation rules
----------------

[](#validation-rules)

The following validation rules are supported:

```
'fail' => array('message' => 'Will always fail.', 'test' => 'return false;'),
'pass' => array('message' => 'Will always pass.', 'test' => 'return true;'),
'not_empty' => array('message' => 'Can not be empty.', 'test' => 'return $value != "";'),
'numeric' => array('message' => 'Must be numeric.', 'test' => 'return is_numeric($value);'),
'mail_address' => array('message' => 'Must be an emailaddress.', 'test' => function($value) { return preg_match('/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $value) === 1; } ),
'match' => array('message' => 'The field does not match.', 'test' => 'return $value == $form[$arg]["value"] ;'),
'must_accept' => array('message' => 'You must accept this.', 'test' => 'return isset($value);'),

```

The validation rule for 'match' is useful when changing password and one field should match another field in the form. The validation rule for 'must\_accept' is useful when the user must accept a license agreement by clicking a checkbox.

Todo
----

[](#todo)

- Layout form elements in grid.
- Style form using LESS and CSS.
- Support all form elements.
- Make page displaying how all form elements look like in different styles.
- Support more validation rules.
- Make example on how you use the validation rules.
- Integrate/support with client side validation through js/ajax.
- Support saving partial data of form through js/ajax.
- Check that the form is valid by storing key in session and hidden field and match those.

History
-------

[](#history)

2013-04-22 v0.9.0

- First tag as baseline when moving CForm from Lydia to own repository.

2012-11-26:

- Added validation rule for email address `email_address`. Rewrote `CFormElement::Validate()` to accept anonomous function as validation rule.

2012-11-14:

- Added `CFormElementCheckboxMultiple`.
- Added code example for checkbox-multiple:
    [http://dbwebb.se/kod-exempel/cform/test\_checkbox\_multiple.php](http://dbwebb.se/kod-exempel/cform/test_checkbox_multiple.php)[http://dbwebb.se/kod-exempel/cform/test\_checkbox1.php](http://dbwebb.se/kod-exempel/cform/test_checkbox1.php) (same example but not true multiple choice)

2012-11-13:

- Added `CFormElementCheckbox` and validation rule `must_accept`.
- Added code example for checkboxes:
    [http://dbwebb.se/kod-exempel/cform/test\_checkbox.php](http://dbwebb.se/kod-exempel/cform/test_checkbox.php)

2012-10-05:

- Updated this readme-file and reworked the tutorial at

- Updated the code-example at:

.
..: Copyright 2012-2013 by Mikael Roos ()

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity64

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 ~101 days

Recently: every ~69 days

Total

10

Last Release

3494d ago

Major Versions

v1.9.8 → v2.x-dev2016-10-18

### Community

Maintainers

![](https://www.gravatar.com/avatar/4cac244120f54c02a4fb3186b91323f3f0805dd9daefd0babeb4a82a19232faf?d=identicon)[mikael\_roos](/maintainers/mikael_roos)

---

Top Contributors

[![mosbth](https://avatars.githubusercontent.com/u/169550?v=4)](https://github.com/mosbth "mosbth (7 commits)")

---

Tags

htmleducationForms

### Embed Badge

![Health badge](/badges/mos-cform/health.svg)

```
[![Health](https://phpackages.com/badges/mos-cform/health.svg)](https://phpackages.com/packages/mos-cform)
```

###  Alternatives

[caxy/php-htmldiff

A library for comparing two HTML files/snippets and highlighting the differences using simple HTML.

21520.9M15](/packages/caxy-php-htmldiff)[gregwar/formidable

Formidable, the pragmatic forms library

12062.2k1](/packages/gregwar-formidable)

PHPackages © 2026

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