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

时间:2018-09-26 21:06:41

标签: php html forms joomla

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

Php代码

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

    ?>

HTML代码

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

2 个答案:

答案 0 :(得分:0)

使用$ _GET和$ _POST直接访问数据并不安全,并且在插入数据库之前需要对数据进行过滤。抛开这些,我们必须了解Joomla有它自己的从表单中检索数据的方式。您必须使用JInput来访问数据。首先,您必须以这种方式调用JInput类

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

这是获取任何变量的方法

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

必须使用过滤器以确保代码安全,以便在字母数字输入中,不会误输入特殊字符或执行任何sql injection。有几个过滤器,您可以在此处找到列表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

答案 1 :(得分:0)

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

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