Archive | Docs

RSS feed for this section

System Requirements

PHP Database Form requires web server that supports PHP 5.3 and higher.

  • PHP 5.3 or later
  • Apache, Tomcat, or Microsoft IIS web server

PHP Database Form supports all major databases:

databases_supported

PHP Database Form Supports all major web browsers:

browser_compatibility

Constructor

PHP Database Form constructor takes three parameters. Use this method to create the PHP Database Form object. Usually this is the first line in your code.

Signature:

public function __constructor($sql, $sql_key='id', $sql_table='')

Parameters:

  • $sqlSQL SELECT statement. This is the only SQL statement users needs to implement. The SELECT statement must include the primary key as one of the columns if not using the wildcard start(*) in SELECT statement.
  • $sql_key: The name of the database table primary key. The default is “id”.
  • $sql_tableName of the database table used in the SQL statement. If not defined, the table name is automatically parsed from the SQL statement.

Example:

$dbForm = new C_DatabaseForm("SELECT * FROM employees", "EmployeeID", "employees");

set_label()

set_label(mixed $col, mixed $label) : $this

Set form element label

Parameters

mixed $col
  • Database table column name
mixed $label
  • Label

set_dimension()

set_dimension(mixed $col, int $cols, int $rows) : $this

Set control dimension width and height. Note that this is not the same as set_form_dimension().

It is used with text type only. For column type text, the width is translated to “size”, its height is ignored. for text area, the width is translated to “cols” and height to “rows”

Parameters

mixed $col
  • Database table column name
int $cols
  • If the column is a text box, it’s the size that represents number of characters. If the column is a textarea, it’s the value for cols attribute in textarea.
int $rows
  • Optional. Number of rows in a textarea (only)

set_form_dimension()

set_form_dimension(mixed $f_width, string $f_height) : $this|void

Set form width and height. Overwrites parent definition for template.

Parameters

mixed $form_width
  • Form width
string $form_height
  • Form height

set_default()

set_default(mixed $col, string $default) : $this

Set control default value for a field

Parameters

mixed $col
  • Database table column name
string $default
  • Default value

set_readonly()

set_readonly(array $cols) : $this

Set one more more columns as read only field. Note that the parameter is an array.

Parameters

array $cols
  • Column name(s)

set_required()

set_required(array $cols) : $this

Set required fields.  The parameter is an array that can take one or more fields.

Parameters

array $cols
  • Columns name(s)

set_hide()

set_hide(mixed $col) : $this

Hide a field on the form from displaying with CSS display:none. Note that the field still exists on the form but not visible.

Do not use this field to hide sensitive information such as password.

Parameters

mixed $col
  • Database table column name

set_placeholder()

set_placeholder(mixed $col, mixed $ph_text) : $this

Placeholder text for HTML form element.

Parameters

mixed $col
  • Database table column name
mixed $ph_text
  • Placeholder text

set_border()

set_border(mixed $border_style) : $this

Set form border using CSS stylesheet

Parameters

mixed $border_style
  • border style in CSS

set_ctrltype()

set_ctrltype(mixed $col, mixed $ctrltype, null $keyvalue_pair, bool $multiple) : $this

Set HTML control type of a specific field. Select and Textare control types are automatically determined by the database field char type based on its length. But you can set it otherwise.

Parameters

mixed $col
  • Database table column name
mixed $ctrltype
  • HTML control type.
  • Supported types:
    • text
    • textarea
    • select
    • checkbox
    • passwords
    • button
    • autocomplete
    • wysiwyg
null $keyvalue_pair
  • Key value pair or SQL SELECT(select control type only)
bool $multiple
  • Multiple select (select control type only)

set_maxlength()

set_maxlength( $col,  $maxlength)

Set max input length for a field

Parameters

mixed $col
  • Database table column name
int $maxlength
  • max numbers of characters allowed

 

set_editrule()

set_editrule(mixed $col, mixed $rule_func) : $this

Custom data validation rules. The 2nd parameter is a the JavaScript function name used for data validation.

Parameters

mixed $col
  • Column name
mixed $rule_func
  • Data rule validation JavaScript

display()

display(bool $render_content)

Display our database form. This should be LAST method to call.

Parameters

bool $render_content
  • Whether to display the form or hold it in PHP buffer to be displayed later. Default to true.

load_form()

load_form(mixed $key) : $this

Load an existing entry from DB.

Parameters

mixed $key
  • A database table primary key value. Zero to load the very entry.

redirect_after_submit()

redirect_after_submit(mixed $url) : $this

Redirect form after submit. It does not check whether the submit is success.

Parameters

mixed $url
  • Redirect URL after successful form submit

add_group_header()

add_group_header(mixed $before_col, mixed $header) : $this

Add caption to a subgroup. This adds visual elements thats help users to better navigate the form

Parameters

mixed $before_col
  • column name that caption goes BEFORE
mixed $header
  • caption

add_captcha()

add_captcha() : $this

Add CAPTCHA* (“Completely Automated Public Turing test to tell Computers and Humans Apart”), a type of challenge-response test used in computing to determine whether or not the user is human.

* phpDatabaseForm uses realperson jQuery plugin available under MIT license.

set_mask()

set_mask(mixed $col, mixed $mask, string $extra_prop)

Provides a general format to text field and enforce it’s structure as the user types in values.

It gives the user an idea about how they should enter the data.

Parameters

mixed $col
  • Column name
mixed $mask
  • Mask pattern
string $extra_prop
  • Optional. Addition properties e.g. “{placeholder: ‘(_)-____’}”. Note must single quote

phpDatabaseForm uses jQuery Mask Input created by Igor Escobar http://igorescobar.github.io/jQuery-Mask-Plugin/ available under MIT license.