mos/cform

Classes for HTML Forms

Installs: 492

Dependents: 3

Stars: 4

Watchers: 3

Forks: 5

Open Issues: 9

Language: PHP

v1.9.1 2014-05-05 15:14 UTC

README

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

By Mikael Roos (me@mikaelroos.se)

License

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

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

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

  • 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

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:

2012-11-13:

2012-10-05: