The SiteForm task for Joomla components creates the MVC files in the frontend for a form from a create table statement in a MySQL file. In the following example, we use a slight (but important) modification of the customers table from the classicmodels database, which can be found here. The code we present below is implemented in the Classic models component, whose extension XML file is found in "TemplateManifests\classicautos.xml".

First we add the following task after the Main task in the extension XML file.

<task name="SiteForm">
  <parameters>
	<table>customers</table>
	<nameObject>customer</nameObject>
	<message>Displays a form that allows people to add customers.</message>
  </parameters>
</task>

The above code tells the program to create MVC files named using the nameObject, customer, based on the table, customers table. Both these parameters are necessary for the task to run correctly.

Now we tell the program where the "customers" table could be found. Note if the BasicBackend task was already created for the "customers" table, then this step can be skipped, as it was already done for that task. We inform the program by creating a MySQL file, named "classicautos_database.sql", with a create table statement for the "customers" table. In our example, the SQL file contains the folloing code.

DROP TABLE IF EXISTS `#__customers`;

CREATE TABLE `#__customers` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `customerName` varchar(50) NOT NULL,
  `contactLastName` varchar(50) NOT NULL,
  `contactFirstName` varchar(50) NOT NULL,
  `phone` varchar(50) NOT NULL,
  `addressLine1` varchar(50) NOT NULL,
  `addressLine2` varchar(50) DEFAULT NULL,
  `city` varchar(50) NOT NULL,
  `state` varchar(50) DEFAULT NULL,
  `postalCode` varchar(15) DEFAULT NULL,
  `country` varchar(50) NOT NULL,
  `salesRepEmployeeNumber` int(11) DEFAULT NULL,
  `creditLimit` decimal(10,2) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `salesRepEmployeeNumber` (`salesRepEmployeeNumber`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

The primary key must be an integer, named "id", and set to AUTO_INCREMENT, as above, for the generated files to work correctly. See Component MySQL File for additional details on the currently supported MySQL syntax. Note that the above code will be used by the Joomla Installer to create the "customers" table when the Classic models component is first installed.

After saving the contents of the above file in the "TemplateManifests" folder, the following line is then added to the parameters section of the "TemplateManifests\classicautos.xml" file, so that the program can find it.

<mySqlFile relUri="true">classicautos_database.sql</mySqlFile>

The attribute relUri="true" tells the program that the MySQL file is in the same folder as the extension XML file.

In conclusion, when the extension file is run, it will create MVC files in the frontend allowing the user to add entries to the "customers" table from the site. The "customers" table will also be created using the above MySQL code when the Classic models component is first installed. Additional customization of the fields extracted from the "customers" table can be made when the extension file is run.