For my web site (joomla) I need a form which after submission is going to execute somme PHP code. I didn't found any form component in the joomla extensions so I tried to make my own component.
I have followed this tutorial but I am blocked because I don't understand how to display and to control my form.
Here is the structure of my component
And here some code I have written. formff.xml
<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="3.0" method="upgrade">
<name>Form FF!</name>
<!-- The following elements are optional and free of formatting constraints -->
<creationDate>Septembre 2019</creationDate>
<author>Rémi</author>
<authorEmail>contact@monsite.fr</authorEmail>
<authorUrl>www.monsite.fr</authorUrl>
<copyright>Copyright Info</copyright>
<license>License Info</license>
<!-- The version string is recorded in the components table -->
<version>0.0.1</version>
<!-- The description is optional and defaults to the name -->
<description>Description of the Form FF component ...</description>
<update> <!-- Runs on update; New since J2.5 -->
<schemas>
<schemapath type="mysql">sql/updates/mysql</schemapath>
</schemas>
</update>
<!-- Site Main File Copy Section -->
<!-- Note the folder attribute: This attribute describes the folder
to copy FROM in the package to install therefore files copied
in this section are copied from /site/ in the package -->
<files folder="site">
<filename>index.html</filename>
<filename>formff.php</filename>
<filename>controller.php</filename>
<folder>views</folder>
</files>
<administration>
<!-- Administration Menu Section -->
<menu link='index.php?option=com_formff'>Form FF!</menu>
<!-- Administration Main File Copy Section -->
<!-- Note the folder attribute: This attribute describes the folder
to copy FROM in the package to install therefore files copied
in this section are copied from /admin/ in the package -->
<files folder="admin">
<!-- Admin Main File Copy Section -->
<filename>index.html</filename>
<filename>formff.php</filename>
<!-- SQL files section -->
<folder>sql</folder>
</files>
</administration>
</extension>
There is no particular code in the admin folder since all the display is for the site. So I will just show the code in the site folder
formff.php
defined('_JEXEC') or die('Restricted access');
// Get an instance of the controller prefixed by FormFF
$controller = JControllerLegacy::getInstance('FormFF');
// Perform the Request task
$input = JFactory::getApplication()->input;
$controller->execute($input->getCmd('task'));
// Redirect if set by the controller
$controller->redirect();
controller.php
defined('_JEXEC') or die('Restricted access');
class FormFFController extends JControllerLegacy
{
}
view.html.php
defined('_JEXEC') or die('Restricted access');
class FormFFViewFormFF extends JViewLegacy
{
/**
* Display the From FF view
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return void
*/
function display($tpl = null)
{
// Assign data to the view
$this->msg = 'Formulaire';
// Display the view
parent::display($tpl);
}
}
default.php
defined('_JEXEC') or die('Restricted access');
?>
<h1><?php echo $this->msg; ?></h1>
default.xml
<?xml version="1.0" encoding="utf-8"?>
<metadata>
<layout title="COM_FORMFF_FORMFF_VIEW_DEFAULT_TITLE">
<message>COM_FORMFF_FORMFF_VIEW_DEFAULT_DESC</message>
</layout>
</metadata>
I understood I can build forms by usign this kind of xml file
default.xml
<?xml version="1.0" encoding="UTF-8"?>
<form>
<fields name="champs">
<fieldset name="ident">
<field
type="text"
name="clientnale"
id="clientnameff"
label="Name"
description="Enter your name"
size="80"
maxLength="255" />
</fieldset>
</fields>
</form>
But I really don't know what to do to display and handle the results of my form
Any ideas??
Remi
where is your models ? you control how your form is displayed via default.php, you can use JTable to map data to database
//In your view.html.php $this->msg is your variable
$this->msg = 'Formulaire';
// In your default.php $this->msg is where your variable is being displayed
<h1><?php echo $this->msg; ?></h1>
//But is is better to use a standard controls to display your
// form for example you can add this to your default.php file
// you should replace 'msg' by your actual fields in your xml form
<div class="control-group">
<div class="control-label"><?php echo $this->form->getLabel('msg');?></div>
<div class="controls"><?php echo $this->form->getInput('msg'); ?></div>
</div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.