【问题标题】:How to create and display/handle a form in Joomla 3.x如何在 Joomla 3.x 中创建和显示/处理表单
【发布时间】:2019-08-29 11:11:47
【问题描述】:

对于我的网站 (joomla),我需要一个表单,提交后将执行一些 PHP 代码。我在 joomla 扩展中没有找到任何表单组件,所以我尝试制作自己的组件。

我关注了this tutorial,但我被屏蔽了,因为我不明白如何显示和控制我的表单。

这是我的组件的结构

see here

这里有一些我写的代码。 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>

admin 文件夹中没有特定代码,因为所有显示都是针对该站点的。所以我将只显示站点文件夹中的代码

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>

我知道我可以通过使用这种 xml 文件来构建表单

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>

但我真的不知道该怎么做才能显示和处理我的表单结果

有什么想法吗??

雷米

【问题讨论】:

  • 请加入Joomla Stack Exchange,并请始终在此处发布所有 Joomla 问题。

标签: php xml joomla3.0


【解决方案1】:

你的模型在哪里? 您可以通过 default.php 控制表单的显示方式,您可以使用 JTable 将数据映射到数据库

//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>   

【讨论】:

  • 我没有模型,我不确定是否需要模型。我应该在 default.php 中添加什么来显示我的表单?
  • 您的 view.html.php 包含您的数据,而您的 default.php 就像一个显示数据的模板;您的 view.html.php 还负责添加侧边栏、顶栏按钮...
  • @pho 如果您能够为 Joomla 问题提供支持,请加入 Joomla Stack Exchange 并四处看看。
  • 我会@mickmackusa
猜你喜欢
  • 2023-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-03
  • 1970-01-01
  • 1970-01-01
  • 2013-04-16
相关资源
最近更新 更多