Hi,
of course jform can be used in an module.
Tip: Have a close look at mod_qlform and its class "modelQlForm" in modules/mod_qlform/classes/modelQlForm.php
See here:
http://extensions.joomla.org/extensions/contacts-and-feedback/forms/20770?qh=YToyOntpOjA7czo2OiJxbGZvcm0iO2k6MTtzOjc6InFsZm9ybXMiO30%3Dmod_qlform does exactly, what you want to code - except that you will feed it with a real xml file, while mod_qlform is fed from a param with xml data.
Maybe you don't need an extra class and you can use jModelForm directly. I think, that might work, too:-)
I wanted to look up the JModelForm in the developer's documentation, but somehow they've changed the docs; so I cannot get to the description of the jModelForm class with all its method.
Question: Does anyone know, where to find the the description of the classes and methods or at least the old docu?
Greetings
Mareike
<?php
/*somewhere include the class bla bla*/
/*1* calling the form*/
$obj_form=new modelYourClassName();
$obj_form->form_name='someFormName';
$obj_form->str_xml=$str_xml;
$form=$obj_form->getForm();
/*following you see the class to be included*/
/**
* @package mod_qlform
* @copyright Copyright (C) 2013
ql.de All rights reserved.
* @author Mareike Riegel
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
jimport('joomla.application.component.modelform'); /*import the JModelForm class*/
class modelYourClassName extends JModelForm
{
/**
* Method for getting the form from the model.
*
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
* @return mixed A JForm object on success, false on failure
*/
public function getForm($data = array(), $loadData = true)
{
// Get the form.
if (!isset($this->form_name))$this->form_name='form'.md5(rand(0,1000));
$form = $this->loadForm($this->form_name, $this->str_xml, array('control' => 'jform', 'load_data' => false));
if (empty($form)) return false;
return $this->form=$form;
}
/**
* Method to check data via jForm->validate
*
* @param array $data An array of data (post data) to be validated
* @return bool true on success, false on failure
* @since 1.6
*/
function check($data)
{
$form=$this->getForm();
if (1==$form->validate($data)) return true;
else
{
$this->formErrors=$form->getErrors();
return false;
}
}
/**
* Method to bind data back to form after failed validation
*
* @param array $data An array of data (post data) to be filled in form
* @return bool true on success, false on failure
* @since 1.6
*/
public function fillForm($data)
{
//echo "<pre>";print_r($data);
$form=$this->getForm();
if ($form->bind($data)) return $this->form=$form; else return false;
}
}