439
edits
| Line 347: | Line 347: | ||
=== Input forms === | === Input forms === | ||
CustomFields provides a neat way to print input fields that are adapted to the SQL data type of your custom fields as well as the possible and formatted values (for example: a not null enum will be printed as a HTML select list without an empty option). | |||
showInputField($field,$currentvalue=null,$moreparam='') | So you don't have to bother how your data will be presented to the user nor how it will be processed. | ||
=== Printing an input form adapted to the field's data type === | |||
showInputField() is a sort of converter customfieldstructure -> HTML input field. | |||
Use the showInputField() method to print the right input form for a custom field. | |||
<source lang="php"> | |||
print $customfields->showInputField($field, $currentvalue=null, $moreparam=''); | |||
</source> | |||
showInputField() takes 3 parameters: | |||
* $field is a CustomFields structure object (eg: returned by fetchFieldStruct()) and is necessary to detect the right datatype and the possible values. | |||
* $currentvalue is the current value if you want to preselect a value (for example if the user already defined a value, you can reload it here). This is optional, in case it is not defined, either a null/empty value will be chosen, or either the default value defined when creating the custom field. | |||
* $moreparam is used to add more HTML attributes, if you want for example to add some css styling or whatever you want. | |||
showInputField() only prints ONE HTML input field, thus you have to enclose it/them by your own HTML form. | |||
eg: | |||
<source lang="php"> | |||
print '<form method="get" action="?">'; | |||
print '<input type="hidden" name="customtoken" value="ABCDEFGH" />'; // example of a custom hidden HTML input field, that can be used to pass a token for example | |||
// Loop over each custom fields (you have to load them before with $customfields->fetchAllFieldsStruct() | |||
foreach ($customfields->fields as $field) { | |||
print $customfields->showInputField($field, $currentvalue=null, $moreparam=''); | |||
} | |||
print '</form>'; | |||
</source> | |||
You can also store the resulting HTML input field and process it by a regexp for example: | |||
<source lang="php"> | |||
$myhtmlfield = $customfields->showInputField($field, $currentvalue=null, $moreparam=''); | |||
preg_replace($myhtmlfield, ..., ...); | |||
</source> | |||
=== Printing an input form for a custom field === | |||
showInputForm() is a function used to print a single (and only one!) custom field with an adapted HTML input field, but enclosed by a HTML form. This is used for example when you want to allow to edit a single custom field but not the others. | |||
showInputForm() is in fact a wrapper for showInputField(), thus it will call showInputField() and simply enclose it by a form. | |||
<source lang="php"> | |||
print $customfields->showInputForm($id, $field, $currentvalue=null, $idvar='id', $page=null, $moreparam=''); | |||
</source> | |||
=== Printing in documents === | === Printing in documents === | ||
edits