Drop Shadow

Custom forms

If you want to customize your form by submitting multiple tables or by specifying exactly where each field displays, you’ll still need to tell the plug-in where the form begins and ends.

Multiple forms on a page

If you have more than one displayForm on a page, but you want to have only a single submit button for all of them, you’ll need to tell the plug-in where the combined forms start and where the combined forms end. Use startForm or endForm for this.

<? $db->startForm(); $db->displayForm(); $db->table('albums'); $db->displayForm(); $db->endForm(); ?>

The endForm method will automatically put in the necessary submit button.

Normally your form field names are the same as the column they go into. But when you have multiple forms on a page, sometimes you’ll have conflicting column names. You can attach a form field to a column using “setFieldName()". For example, if you have a “name” column in your main table and in the related “contacts” table, you’ll have to use something like:

<? $db->table('contacts'); $db->setFieldName('name', 'contactname'); ?>

Form Fields

If you don’t want to use displayForm or displayFormList, you can create your forms as you would any other PHP page’s forms, but the SQL plug-in can also create form fields for you, as a list item, as a table row, as bare text, or as a table header/table cell combination.

<? $db->makeListItem('fieldname'); $db->makeTableRow('fieldname'); $db->makeInput('fieldname'); $db->makeTableInput('fieldname'); ?>

You must place makeListItem and makeTableRow inside of a list or table, respectively. You can place makeInput inside any element that can contain text, such as a paragraph. And makeTableInput must go inside of a table row.

The methods will automatically create a label and input element for that field. If you need a custom label, add it as a second parameter. Note that the labels created from the field name have a colon appended to the end; if you need this for your custom label, you’ll need to add it yourself (sometimes the reason for a custom label is to avoid the colon after, for example, a question mark).

If you are creating more than one list item or table row at once, you can use the makeListItems or makeTableRows methods. They take a list of fields.

<table class="newperson"> <? $db->makeTableRows(array('field1', 'field2', 'field3', 'field4')); ?> </table>

Or, as a list:

<ul class="newperson"> <? $db->makeListItems(array('field1', 'field2', 'field3', 'field4')); ?> </ul>

This will create a series of list items or table rows, with automatic labels and accessible form elements.

Form field labels

If you need the label for a form field, use:

$label = $db->getFieldLabel('field');

You can use this in JavaScript, for example, to reference a field element.

Using specific values

There are several options for this function. You can give getFormHTML() the value to use. For example, you can get it from a previously acquired row from row() or rows():

<? //this will use the value of the same name from the posted form or focus $db->getFormHTML('fieldname'); //this will use the value of the same name from given array $person = $db->row(55); $db->getFormHTML('fieldname', $person); ?>

If you want to display more than one record, and need to update any of them, add a third option to getFormHTML(): the value of the row ID that corresponds to this value:

<? $db->getFormHTML('fieldname', 'fieldvalue', 'rowID'); ?>

And you’ll need to use a special submit button so that the database knows to update or insert the data on submission:

<? $db->getFormSubmit(); ?>

Custom Text Sizes

If you need to provide a special size for text inputs, use getCustomFormHTML() and provide it the field name and the maximum size you want.

<? $db->getCustomFormHTML('title', 45); ?>

If the title’s size in the database is larger than 45, this will limit the current form to 45 characters. This applies only to the form, not to the database or to form submissions.

If the field uses a textarea, you can provide an array of two numbers; the first number is the number of columns and the second is the number of rows.

Deprecated: Input tag only

If you want to provide everything except the input element, you can use getFormHTML to display the element.

<? $db->getFormHTML('fieldname'); ?>

This will display text fields of the appropriate size, and for enum fields it will display a select list, a radio group, or a checkbox. If are focussed on a record, that record’s value will be used

If you use this method, it will not be accessible. The makeInput, makeTable…, and makeList… methods automatically set the label for you; the label produced by getFormHTML may change according to HTML standards changes or to ensure unique IDs, so you can’t set the ID yourself.