Comment faire un PHP_SELF sous Joomla ?

Réduire
Ce sujet est fermé.
X
X
 
  • Filtrer
  • Heure
  • Afficher
Tout effacer
nouveaux messages

  • [RÉGLÉ] Comment faire un PHP_SELF sous Joomla ?

    Bonjour,

    J'ai un formulaire qui est dans un composant qui a pour but de filtrer les résultats d'une requete SQL.
    Je veux que ce formulaire s'appelle lui même pour afficher la liste des données.

    PHP_SELF en action du formulaire ne semble avoir aucun effet. Est ce qu'il faut utiliser JRoute ? mais je ne connais pas la syntaxe exacte.

    merci de vos conseils


    Code PHP:
    <?php
    /**
     * @version     1.0.0
     * @package     com_eventsearch
     * @copyright   Copyright (C) 2015. All rights reserved.
     * @license     GNU General Public License version 2 or later; see LICENSE.txt
     * @author      ITF <info@itflexsolutions.com> - http://itflexsolutions.com/
     */
    // no direct access
    defined('_JEXEC') or die;

    JHtml::_('behavior.keepalive');

    //Load admin language file
    $lang = JFactory::getLanguage();
    $lang->load('com_eventsearch', JPATH_ADMINISTRATOR);
    $doc = JFactory::getDocument();
    $doc->addScript(JUri::base() . '/components/com_eventsearch/assets/js/form.js');


    ?>
    </style>

    <?php 
    $db 
    =JFactory::getDBO();

    $annee="SELECT distinct annee FROM tbl_classemnt_champ order by annee desc";
    $db->setQuery( $annee );
    $annee_options = $db->loadObjectList();

    $type="SELECT distinct nom_type_equitation from tbl_classemnt_champ";
    $db->setQuery( $type );
    $type_options = $db->loadObjectList();

    $discipline="SELECT distinct nom_discipline from tbl_classemnt_champ";
    $db->setQuery( $discipline );
    $disc_options = $db->loadObjectList();

    $division="SELECT distinct nom_division from tbl_classemnt_champ";
    $db->setQuery( $division );
    $div_options = $db->loadObjectList();

    $indice="SELECT distinct nom_indice from tbl_classemnt_champ";
    $db->setQuery( $indice );
    $ind_options = $db->loadObjectList();

    $province="SELECT distinct nom_province from tbl_classemnt_champ";
    $db->setQuery( $province );
    $pro_options = $db->loadObjectList();


    if (isset(
    $_POST['valider'])) {
    $query="SELECT classement_champ, cav_cheval, id_club_cav, tot_champ, nom_province, nom_type_equitation, nom_discipline, nom_division, nom_indice, annee
            FROM tbl_classemnt_champ
            WHERE annee = "
    .$_POST['annee']." AND nom_province = '".$_POST['province']."' AND nom_type_equitation = '".$_POST['type']."' AND nom_discipline = '".$_POST['discipline']."' AND nom_division = '".$_POST['division']."' AND nom_indice = '".$_POST['indice']."'
            GROUP BY nom_province, nom_type_equitation, nom_discipline, nom_division, nom_indice, annee, classement_champ asc
            "
    ;
    echo 
    $query;
    }
    else
    {
    $query="SELECT classement_champ, cav_cheval, id_club_cav, tot_champ, nom_province, nom_type_equitation, nom_discipline, nom_division, nom_indice, annee
            FROM tbl_classemnt_champ
            GROUP BY nom_province, nom_type_equitation, nom_discipline, nom_division, nom_indice, annee, classement_champ asc
            "
    ;
    }

    $db->setQuery( $query );
    $result = $db->loadObjectList();


    ?>

    <div id="error_messages" style="border: 1px solid #FFF; color:#FF0000; display:none;">
    </div>
    <div>
    <form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']) ?>">
    <table>
        <tr>
        <td>
        <label>Année :</label>
        </td>
        <td>
            <select name="annee" id="annee" >
            <?php
                
    foreach($annee_options as $an)
                {
                    echo 
    '<option value="'.$an->annee.'">'.$an->annee.'</option>';
                }                                    
            
    ?>  
            </select>
        </td>
        <td>
        <label>Province :</label>
        </td>    
        <td>    
            <select name="province" id="province" >
            <?php
                
    foreach($pro_options as $po)
                {
                    echo 
    '<option value="'.$po->nom_province.'">'.$po->nom_province.'</option>';
                }  
                
    ?>  
            </select>        
        </td>
        </tr><tr>
        <td>
        <label>Type équitation :</label>
        </td>
        <td>
            <select name="type" id="type" >
            <?php
                
    foreach($type_options as $typ)
                {
                    echo 
    '<option value="'.$typ->nom_type_equitation.'">'.$typ->nom_type_equitation.'</option>';
                }                                    
            
    ?>  
            </select>
        </td>
        <td>
        <label>Discipline :</label>
        </td>    
        <td>    
            <select name="discipline" id="discipline" >
            <?php
                
    foreach($disc_options as $disc)
                {
                    echo 
    '<option value="'.$disc->nom_discipline.'">'.$disc->nom_discipline.'</option>';
                }  
                
    ?>  
            </select>        
        </td>
        </tr><tr>
        <td>
        <label>Division :</label>
        </td>
        <td>
            <select name="division" id="division" >
            <?php
                
    foreach($div_options as $div)
                {
                    echo 
    '<option value="'.$div->nom_division.'">'.$div->nom_division.'</option>';
                }                                    
            
    ?>  
            </select>
        </td>
        <td>
        <label>Indice :</label>
        </td>    
        <td>    
            <select name="indice" id="indice" >
            <?php
                
    foreach($ind_options as $ind)
                {
                    echo 
    '<option value="'.$ind->nom_indice.'">'.$ind->nom_indice.'</option>';
                }  
                
    ?>  
            </select>        
        </td>    
        </tr>
        </table>
        <input type="button" align="right" name="valider" id="valider" value="Filtrer" />
    </form>

    </div>
    <div class="eventsearch-front-end">
        <table width="100%" style="border: 1px solid #A7A59C;">
            <thead style="border:solid 2px; background-color:lightgrey"> <!-- En-tête du tableau -->
                <tr>
                    <th>Classement</th>
                    <th>Cavalier/Cheval</th>
                    <th>Club</th>
                    <th>Points championnat</th>
                </tr>
            </thead>
            <tbody>
        <?php        
                $row 
    = 1;
        foreach(
    $result as $donnees)
        {
    ?>

            <tr class="<?php echo $row % 2 == 0 ? 'even' : 'odd'; ?>">
            <td id="classement" align="center"><?php echo $donnees->classement_champ; ?></td>
            <td id="cavalier"><?php echo $donnees->cav_cheval; ?></td>        
            <td id="club" align="center"><?php echo $donnees-> id_club_cav; ?></td>
            <td id="points" align="center"><?php echo $donnees->tot_champ; ?></td>        
            </tr>

            <?php
            $row
    ++;
        }
    ?>
            </tbody>
        </table>
    </div>

  • #2
    Re : Comment faire un PHP_SELF sous Joomla ?

    Bonjour

    Sous Joomla, tout est exécuté au travers de index.php. SELF = index.php et ça, je suppose que ce n'est pas ce que tu veux.

    Cela devrait être index.php?option=com_tonComposant&task=UneTache.

    Bonne journée.
    Christophe (cavo789)
    Mon blog, on y parle Docker, PHP, Python, WSL, Joomla, Markdown et plein d'autres choses : https://www.avonture.be/fr​

    Commentaire


    • #3
      Re : Comment faire un PHP_SELF sous Joomla ?

      Bonjour,

      S'agissant d'un composant, la logiqu eMVC veut que l'action soit définie dans le controller, et l'appel se fait effectivement via JRoute en précisant l'action.https://docs.joomla.org/J3.xeveloping_a_MVC_Component

      D'autre part, l'utilisation directe de $_POST ouvre la porte à des risques d'injection. Utiliser la classe JInput pour filtrer les interactions utilisateurs https://api.joomla.org/cms-3/classes/JInput.html
      Pas de demande de support par MP.
      S'il n'y a pas de solution, c'est qu'il n'y a pas de problème (Devise Shadok)

      Commentaire


      • #4
        Re : Comment faire un PHP_SELF sous Joomla ?

        merci ça marche avec Jroute + index.php et nom du composant

        Commentaire


        • #5
          Re : Comment faire un PHP_SELF sous Joomla ?

          Si c'est réglé merci de l'indiquer :
          Mon mot de passe : les huit derniers chiffres du nombre Pi

          Commentaire

          Annonce

          Réduire
          Aucune annonce pour le moment.

          Partenaire de l'association

          Réduire

          Hébergeur Web PlanetHoster
          Travaille ...
          X