简体   繁体   中英

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). if i write something random with echo it gets displayed correctly

Php code

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

    ?>

Html code

<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. Leaving aside that we have to understand that Joomla has its own way of retrieving data from a form. You have to use JInput to access your data. First you have to call the JInput class this way

$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 . There are several filters and the list you can get here https://docs.joomla.org/Retrieving_request_data_using_JInput .

You also have to understand how forms are created and submitted in 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 .

$_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). $_POST should also always work, but, in most cases, the form submissions are stored in a nested array of $_POST.

As others have mentioned, you should use Joomla's function to retrieve $_GET and $_POST values, mainly because these functions are more secure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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