SAutoLoad::addModule('pr2'); SAutoLoad::addModule('xforms');
$xrm = new XFormsRenderModule();
$formXML = file_get_contents("../../content/sampleForm.xml");
$xrm->loadXml($formXML);
To being creating an XForm programmatically, create an instance of the Form class.
$form = new Form();
Adding Text
To add titles demarcating sections of your form, use addText();
$form->addText("Title of the Form Section", "Description of the Form Section");
Adding Form Inputs
To add a form input, use addInput(). Pass in the following, in this order:
To crete a set of checkboxes, you could use the following code to create a "select" input:
$options = array('One', 'Two', 'Three', 'Four', 'Five'); $form->addInput('select', 'My Checkboxes', 'myCheckBox', 'paragraph', true, array('One'), $options, 'full', 'Try clicking on some of the following options...');
To crete a set of radio buttons, you could instead create a "select1" input:
$options = array('One', 'Two', 'Three', 'Four', 'Five'); $form->addInput('select1', 'My Checkboxes', 'myCheckBox', 'paragraph', true, array('One'), $options, 'full', 'Try clicking on some of the following options...');
To crete a dropdown menu, you would use the same code, but with an appearance of 'minimal':
$options = array('One', 'Two', 'Three', 'Four', 'Five'); $form->addInput('select1', 'My Checkboxes', 'myCheckBox', 'paragraph', true, array('One'), $options, 'minimal', 'Try clicking on some of the following options...');
To create a textarea, you would do the following:
$form->addInput('textarea', 'Description', 'description', 'paragraph', false, 'Replace this text to write a description...', '', '', 'Please write a description of yourself');
Generating Form XML Finally, we generate XML using buildForm() and pass that output to the XFormsRenderModule.
$outputXML = $form->buildForm('Submit Test Data');
$xrm->loadXml($outputXML);