Remember that displayForm and displayFormList can handle creating your forms for you, in the same way that display and displayList handle displaying your data for you. These options are for more advanced forms.
Empty entry forms
If you want to display an empty entry form, you can do so with displayBlank and displayBlankRow. For example:
<? $areas->displayList(); echo "<h2>New Entry</h2>\n"; $areas->displayBlankRow(); ?>
Remember that a displayFormList will automatically display an empty row on the bottom of the row list.
Custom help text
If you need a field to have custom help text when displayed in a form, use “setFieldHelp()”:
< $db->setFieldHelp('field', 'help text'); ?>
The help text will appear directly following the field in the form view.
If you want to require some fields not to be empty, set them using “requiredFields()”. For example
<? $required = array('lastname', 'email'); $db->requiredFields($required); ?>
Note that this is a list of the required form fields. The names of the fields will probably match the names of the columns they’re attached to, but if they don’t, it’s the form field name that you want to list here.
Most of the time, your multiple choice fields will be either enum fields or foreign keys, which the plug-in will automatically create multiple-choice answers from. Sometimes, however, your choices are either not as general, or just plain too complex to create with an enum or foreign key.
If that’s the case, you can tell the plug-in that your field’s answers must come from an array that you give it.
$choices = array("Taxman", "Eleanor", "Yellow"); $db->setFieldChoices('song', $choices);
The only listed choices will be "Taxman", "Eleanor", and "Yellow".
This option can also override “enum” and “set” field choices. Remember that if you try to set an enum or set to a value that doesn’t exist in the field’s real choice list, it will fail.
If you need the value to be different from what is displayed, make each item be an array itself. For example:
$choices = array( array(1, "Taxman"), array(2, "Eleanor"), array(6, "Yellow") ); $db->setFieldChoices('song', $choices);
Choices from a query
If the reason you’re doing this is to make use of a complex query, the plug-in can create those value/display pairs for you. Give a query to queryChoices() and it will return an array of arrays. Whatever you put in as the first item in the SELECT statement will be the value; whatever you put in as the second item will be displayed. (Any other items will be ignored.)
$choices = $db->queryChoices($query); $db->setFieldChoices('song', $choices);
If you have a default value for an empty field, specify it using setFieldDefault():
$db->setFieldDefault('song', 'The Song that Would Not Rhyme');
Any value, whether from a form submission or from existing data, will override the default.