USD Logo MySanDiego | Libraries | Bookstore | Find People | A to Z Index | Resources | Jobs
 Prospective Students | Current Students | Alumni, Parents & Friends | Faculty & Employees | Visitors | International
About USDAdmissionsAcademicsNews and EventsAdministrationAthleticsGiving

Custom forms

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:

<? $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

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->getFormHTML('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.