在 Joomla 目录中放置一个简单的可调用 php 脚本的位置

Where to put a simple callable php script in Joomla directory

我有一些 Joomla HTML 内容,其中包含一个简单的 HTML 表单,其结果应该可用于一个简单的 PHP 脚本。

基本上 HTML 形式如下:

<form action="action.php" method="post">

问题是 can/should 我将我的 action.php 脚本放在 Joomla 项目目录中的位置

  1. 我的 form action
  2. 可以调用
  3. 未被 Joomla 更新覆盖

为此你必须创建 joomla 内容插件,使用内容插件你可以处理表单提交操作。

供参考: https://docs.joomla.org/J3.x:Creating_a_content_plugin

我建议为表单创建一个组件。您可能需要处理表单中的输入,并根据表单中的内容执行一些操作,如果有错误,return 表单等

制作组件的最简单方法:

  • 在组件中添加一个文件夹:/components/com_whatever
  • 在文件夹 com_whatever
  • 中添加 php-文件:whatever.php
  • 添加 xml-文件:whatever.xml

whatever.xml 的内容:

<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="3.2.0" method="upgrade">
    <name>Whatever</name>
    <version>1.0.0.0</version>
    <files folder="site">
        <filename>whatever.php</filename>
    </files>
    <administration>
    </administration>
</extension>

whatever.php 的内容:

<?php
defined('_JEXEC') or die;
echo "HELLOOOO";
// or rather some code handling your form data

通过转至 yoursite/administrator/index.php?option=com_installer&view=discover

安装组件

现在您可以从表单到达 whatever.php,使用:

<form action="index.php?option=com_whatever" method="post">

您可以并且可能应该在您的组件中做很多事情,但这是最低限度的。

PS: 可以安装一个表单组件,有很多。或者,您可以使用组件构建器来创建表单,然后您还可以获得管理工具来处理传入的数据。