简体   繁体   English

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

[英]Methods $_GET and $_POST doesn't work on Joomla

The page gets executed by clicking on the submit button of the form but I can't get the data insered into the form. 通过单击表单的提交按钮可以执行该页面,但是我无法将数据插入到表单中。 The php and the html code work if they are uploaded on the server like a file outside Joomla, but the code doesn't work if the html code gets uploaded on the Joomla articles (inside the database). 如果将php和html代码像在Joomla之外的文件一样上传到服务器上,则可以工作,但是如果将html代码上传到Joomla文章(在数据库内部)中,则该代码不起作用。 if i write something random with echo it gets displayed correctly 如果我用回声随机写一些东西,它将正确显示

Php code 邮递区号

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

    ?>

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

Directly accessing data with either $_GET and $_POST is not safe and data needs to be filtered before you insert into database. 使用$ _GET和$ _POST直接访问数据是不安全的,并且在插入数据库之前需要对数据进行过滤。 Leaving aside that we have to understand that Joomla has its own way of retrieving data from a form. 抛开这些,我们必须了解Joomla有它自己的从表单中检索数据的方式。 You have to use JInput to access your data. 您必须使用JInput来访问数据。 First you have to call the JInput class this way 首先,您必须以这种方式调用JInput类

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

This is the way to get any variable 这是获取任何变量的方法

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

Filter is necessary to make your code safe so that in Alhanumeric input none by mistake enters special characters or do any sql injection . 为使代码安全,必须使用过滤器,以便在字母数字输入中不会误输入特殊字符或进行任何SQL注入 There are several filters and the list you can get here https://docs.joomla.org/Retrieving_request_data_using_JInput . 有几个过滤器,您可以在这里找到列表https://docs.joomla.org/Retrieving_request_data_using_JInput

You also have to understand how forms are created and submitted in Joomla. 您还必须了解如何在Joomla中创建和提交表单。 You can go through this link to know more https://docs.joomla.org/J3.x:Developing_an_MVC_Component/Adding_a_front-end_form . 您可以通过此链接了解更多https://docs.joomla.org/J3.x:Developing_an_MVC_Component/Adding_a_front-end_form

$_GET should always work, regardless - if you can't see the values, then this means that the page that you are checking the $_GET array is a different page (which is typically what happens when you check the $_GET array on the submitted page). $ _GET应该始终有效,无论如何-如果看不到这些值,则意味着您正在检查$ _GET数组的页面是另一个页面(通常,当您在$ _GET数组上检查$ _GET数组时会发生这种情况。提交页面)。 $_POST should also always work, but, in most cases, the form submissions are stored in a nested array of $_POST. $ _POST也应始终有效,但是在大多数情况下,表单提交存储在$ _POST的嵌套数组中。

As others have mentioned, you should use Joomla's function to retrieve $_GET and $_POST values, mainly because these functions are more secure. 正如其他人提到的那样,您应该使用Joomla函数来检索$ _GET和$ _POST值,主要是因为这些函数更安全。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM