constructor
constructor - Creates a clonefish instance to represent a form.
Description
class clonefish { clonefish clonefish() ( string $name, string $action, string $method [, mixed $db = null, string $dbtype = 'mysql' [, mixed $refid = null ]] ) }
Creates a clonefish instance to represent a form.
Parameters
name
The name=""
parameter of the form tag. Also used to name the JavaScript validation function, as multiple forms on the same page need to have separate validation functions.
action
The action=""
parameter of the form tag (the script name the form will be submitted to)
method
The method=""
parameter of the form tag (GET or POST)
db
If you use dynamic fields or the database validation, here you'll need to pass a connection resource or a database connection reference:
- if you use the 'mysql' database wrapper (which uses the built-in mysql functions like mysql_query() ), you are not required to use this parameter. If the link identifier is not specified (or is null), the last link opened by mysql_connect() is assumed.
- if you use the 'adodb' database wrapper, pass an AdoDB object
- if you use the 'peardb' database wrapper, pass a Pear DB object
- if you use the 'mdb2' database wrapper, pass a Pear MDB2 object
- if you use the 'pdo' database wrapper, pass a PHP PDO object
dbtype
This parameter allows you to define the database wrapper to use. It determines the filename and the class name of the wrapper, so if you want to create your own wrapper, follow this naming convention:
dbwrapper_dbtype.php
class DBWrapperdbtype
Creating a wrapper class is very easy: feel free to check the classes already available, and create your own! Currently the available following options are available: mysql
, pdo
, adodb
, peardb
, mdb2
refid
This parameter is used by the selectDynamic element. When an ID is passed, you can reuse it in the 'valuesql'
setting of a selectDynamic element to pre-select options of a multiple select. In a typical 1-N database relation this is the ID of the single ("1") side of the relation.
Return Values
Returns a clonefish object on success. The constructor dies with an error message if an error occurs.
Examples
Example 1: create a form without a database connection.
<?php $form = new clonefish( 'loginform', 'login.php', 'POST' ); ?>
Example 2: create a form with an implicit MySQL connection
<?php // Clonefish defaults to the MySQL database // type, so both of these lines allow using database // related elements. You need to have an open MySQL // connection. $form = new clonefish( 'loginform', 'login.php', 'POST' ); $form = new clonefish( 'loginform', 'login.php', 'POST', null, 'mysql' ); ?>
Example 3: create a form with an explicit database connection
<?php // If you use multiple connections or a different database // wrapper, just pass your database link resource or // connection object: $mysql_link = mysql_connect( [...] ); $form = new clonefish( 'loginform', 'login.php', 'POST', $mysql_link, 'mysql' ); $form = new clonefish( 'loginform', 'login.php', 'POST', $conn_object, 'adodb' ); ?>
form validation for developers!
clonefish is a proven, mature form generator class that helps PHP developers to create, validate and process secure, flexible and easy-to-maintain formslearn more