方法 $_GET 和 $_POST 在 Joomla 上不起作用



通过单击表单的提交按钮来执行页面,但我无法将数据输入表单。 如果 php 和 html 代码像 Joomla 外部的文件一样上传到服务器上,则代码可以工作,但如果 html 代码上传到 Joomla 文章(在数据库内(,则代码不起作用。 如果我用 echo 随机编写一些东西,它会正确显示

菲律宾代码

<php
$codice = $_GET["sblocca"];
echo $codice;
?>

网页代码

<form action="/home/arioxurl/public_html/scriptPHP/ChiusuraPrestazione/generaFattura.php" class="form-horizontal" method="get">
<fieldset>

<!-- Form Name -->
<legend>Chiusura prestazione</legend>

<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="sblocca">inserisci il codice a sei cifre per sbloccare il pagamento</label> 
<div class="col-md-4">
<input  name="sblocca" type="text" placeholder="XXXXXX" class="form-control input-md" required="">
<>
<>

<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="NumFatt">inserisci il numero della fattura, deve essere incrementato di uno rispetto all'ultima generata (anche all'esterno di dashup)</label> 
<div class="col-md-4">
<input id="NumFatt" name="NumFatt" type="text" placeholder="numero fattura es: 312" class="form-control input-md">
<>
<>

<!-- Multiple Checkboxes -->
<div class="form-group">
<label class="col-md-4 control-label" for="Conferma"></label>
<div class="col-md-4">
<div class="checkbox">
<label for="Conferma-0">
<input type="checkbox" name="Conferma" id="Conferma-0" value="1">
Conferma numero fattura
</label>
<>
<>
<>

<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="Download"></label>
<div class="col-md-4">
<button name="annulla" class="btn btn-info">Annulla</button>
<input type="submit" value="Sblocca pagamento e scarica fattura" class="btn btn-primary">
<>
<>

</fieldset>
</form>

使用 $_GET 和 $_POST 直接访问数据是不安全的,在将数据插入数据库之前需要过滤数据。除此之外,我们必须了解Joomla有自己的方式从表单中检索数据。您必须使用 JInput 才能访问您的数据。首先,您必须以这种方式调用 JInput 类

$jinput = JFactory::getApplication()->input;

这是获取任何变量的方法

$variable = $jinput->get('varname', 'default_value', 'filter');

过滤器对于使您的代码安全是必要的,以便在 Alhanumeric 输入中没有人错误地输入特殊字符或执行任何 sql 注入。有几个过滤器和列表,你可以在这里得到 https://docs.joomla.org/Retrieving_request_data_using_JInput。

您还必须了解如何在Joomla中创建和提交表单。您可以通过此链接了解更多信息 https://docs.joomla.org/J3.x:Developing_an_MVC_Component/Adding_a_front-end_form。

$_GET 应该始终有效,无论如何 - 如果您看不到值,则这意味着您正在检查 $_GET 数组的页面是不同的页面(当您检查提交的页面上的 $_GET 数组时通常会发生这种情况(。 $_POST 也应该始终有效,但在大多数情况下,表单提交存储在 $_POST 的嵌套数组中。

正如其他人所提到的,你应该使用 Joomla 的函数来检索 $_GET 和 $_POST 值,主要是因为这些函数更安全。

最新更新