Using the XoopsForm library
For a visual overview of the various classes used in constructing forms check out the UML Class Diagram.
XOOPS comes with a selection of Form Classes, ready to use.
Using the form classes starts with including the form classes through the xoopsformloader.php:
include XOOPS_ROOT_PATH."/class/xoopsformloader.php";
After this include, you are able to use any of the XoopsForm classes.
Using XoopsForm Classes
The order of instantiating the XoopsForm elements is not important, but we'll start off with making the Form object:
$testform = new XoopsForm('Title of form', 'name of form', 'url to action-receiving page', 'POST/GET method');
The form defaults to POST method if none chosen. Available forms are XoopsThemeForm, XoopsTableForm? and XoopsSimpleForm, all of which inherits from XoopsForm - XoopsForm itself is an abstract class and should not be instantiated on its own, but instead one of the child classes, e.g.
$testform = new XoopsSimpleForm('Title of form', 'name of form', 'url to action-receiving page', 'POST/GET method');
Next, we want to add elements to the form. Available elements are:
1. XoopsFormLabel 2. XoopsFormSelect 3. XoopsFormText 4. XoopsFormCheckBox 5. XoopsFormRadio 6. XoopsFormHidden 7. XoopsFormHiddenToken 8. XoopsFormFile 9. XoopsFormPassword 10. XoopsFormButton 11. XoopsFormTextArea 12. XoopsFormDhtmlTextArea 13. XoopsFormDateTime
Elements are added with
$testform->addElement(&$element, $required = false);
If you want to add more to the element (accesskey or similar) you should first make the object, then set the accesskey etc. before sending the object with the addElement method. Otherwise, you can instantiate the object directly in the addElement method, e.g. like this:
$testform->addElement(new XoopsFormText($name, $desc, $size, $maxlength, $value));
Add the elements you want and finish off the form with a
$testform->display();
Back to the Main Page

![[Main Page]](/modules/mediawiki/images/mediawiki.png)






