Forum CMS Made Simple FR

Version complète : [Résolu] Problème de variable params depuis un formulaire
Vous consultez actuellement la version basse qualité d’un document. Voir la version complète avec le bon formatage.

Rian

Citation :#~~~~~ DEBUT BLOC A NE PAS SUPPRIMER ~~~~~
#~ Version du CMS: #1.9.4.3
#~ Url du site : localhost
#~ Hébergeur / Soft : mamp
#~ Informations Système :
#~ ----------------------------------------------
#~ Cms Version: 1.9.4.3
#~ Installed Modules:
#~ CMSMailer: 2.0.1
#~ FileManager: 1.1.0
#~ MenuManager: 1.7.6
#~ ModuleManager: 1.4.2
#~ News: 2.11.4
#~ nuSOAP: 1.0.2
#~ Printing: 1.1.2
#~ Search: 1.6.10
#~ ThemeManager: 1.1.4
#~ TinyMCE: 2.8.4
#~ BerdujImmo: 0.9.3
#~ SEOTools: 1.2
#~ Config Information:
#~ php_memory_limit:
#~ process_whole_template: false
#~ output_compression: false
#~ max_upload_size: 32000000
#~ default_upload_permission: 664
#~ url_rewriting: mod_rewrite
#~ page_extension: .html
#~ query_var: page
#~ image_manipulation_prog: GD
#~ auto_alias_content: true
#~ locale:
#~ default_encoding: utf-8
#~ admin_encoding: utf-8
#~ set_names: true
#~ Php Information:
#~ phpversion: 5.2.13
#~ md5_function: On (Vrai)
#~ gd_version: 2
#~ tempnam_function: On (Vrai)
#~ magic_quotes_runtime: Off (Faux)
#~ E_STRICT: 0
#~ memory_limit: 32M
#~ max_execution_time: 30
#~ output_buffering: On
#~ safe_mode: Off (Faux)
#~ file_uploads: On (Vrai)
#~ post_max_size: 32M
#~ upload_max_filesize: 32M
#~ session_save_path: /Applications/MAMP/tmp/php (0775)
#~ session_use_cookies: On (Vrai)
#~ xml_function: On (Vrai)
#~ Server Information:
#~ Server Api: apache2handler
#~ Server Db Type: MySQL (mysql)
#~ Server Db Version: 5.1.44
#~ ----------------------------------------------
#~~~~~ FIN BLOC A NE PAS SUPPRIMER ~~~~~



Bonjour à tous,

Je ne suis pas un grand connaisseur de MS, mais j'ai réussi à m'y faire à partir d'un module déjà existant et d'ajouté des features mais alors la, je bloque sur un truc stupide ...

J'ai créer un template classique :
Code :
{$start_form}

<div>{$input_checkbox_type}</div>
<div>{$input_checkbox_prix}</div>
<div>{$input_checkbox_surface}</div>
<div>{$input_checkbox_piece}</div>
<div>
    Votre email: {$input_email}
</div>

{$submit}
{$end_form}

Et l'action qui lui correspond :
Code :
<?php
/**
*
* This is an example of a simple method to display
* database data on page using a template.
*
* If the "skeleton_id" parameter is set, this page will
* display only that single record. Otherwise, it will display
* one page worth of records. This is really silly in this case,
* because the view is identical. If you have a more complex
* record though, you could do something useful.
*
* Note that it uses a template, and is thus very powerful,
* even if it's simple.
*/

/**
* For separated methods, you'll always want to start with the following
* line which check to make sure that method was called from the module
* API, and that everything's safe to continue:
*/

if (!isset($gCms)) exit;

$application= $params['application'];
if (!$application) $application=1;


$dest_page=( $params['display_page'] ) ? $params['display_page'] : $gCms->variables['page_name'];


$smarty->assign('start_form', $this->CreateFormStart($id, 'set_alerte', $returnid));


$items = $this->getTypeListForCheckBox();
$str = "";
foreach ($items as $key=>$value)
{
    $str .= $this->CreateInputCheckbox($id, "type".$value,  $value, 0 ) . " " . $key . " ";
}
$smarty->assign('input_checkbox_type',    $str);

    
$items = $this->getPrixListForCheckBox(1);
$str = "";
foreach ($items as $key=>$value)
{
    $str .= $this->CreateInputCheckbox($id, "prix".$value,  $value, 0 ) . " " . $key . " ";
}
$smarty->assign('input_checkbox_prix',    $str);

    
$items = $this->getSurfaceListForCheckBox();
$str = "";
foreach ($items as $key=>$value)
{
    $str .= $this->CreateInputCheckbox($id, "surface".$value,  $value, 0 ) . " " . $key . " ";
}
$smarty->assign('input_checkbox_surface',    $str);

    
$items = $this->getPieceListForCheckBox();
$str = "";
foreach ($items as $key=>$value)
{
    $str .= $this->CreateInputCheckbox($id, "piece".$value,  $value, 0 ) . " " . $key . " ";
}
$smarty->assign('input_checkbox_piece',    $str);



$smarty->assign('input_email',    $this->CreateInputText($id,'email',    '',30));


$smarty->assign('submit',// $this->CreateInputHidden($id,'display_page',$dest_page )
                        //. $this->CreateInputHidden($id,'application',$application)
                        //. $this->CreateInputHidden($id,'page_search',1)
                        /*.*/ $this->CreateInputSubmit($id, 'submit', $this->Lang('submit'))
                        //. $this->CreateInputSubmit($id, 'reset', $this->Lang('reset'))
                        );

$smarty->assign('end_form', $this->CreateFormEnd());

    echo $this->ProcessTemplate('alerte_template.tpl');
?>

Lorsque j'envoie le formulaire, si je fais un var_dump de $params, je ne récupère pas du tout mes checkbox et mon champs email ...

Alors je me suis dis que j'avais mal fait, donc je regarde ca qui fonctionne :

Code :
if (!isset($gCms)) exit;

$application= $params['application'];
if (!$application) $application=1;

if ($params['page_search']) $this->setActiveSearchPage($application, $params['page_search']);
$dest_page=( $params['display_page'] ) ? $params['display_page'] : $gCms->variables['page_name'];


$smarty->assign('start_form', $this->CreateFormStart($id, 'set_filters', $returnid));
$smarty->assign('input_annonce_secteur',    $this->CreateInputSelectList ($id, 'secteur', $this->getSecteurListForSelect(true) ,array($this->activeSearchFilters[$application]['secteur']),1,'',false));
$smarty->assign('input_annonce_type',        $this->CreateInputSelectList ($id, 'type', $this->getTypeListForSelect(true) ,array($this->activeSearchFilters[$application]['type']),1,'',false));
$smarty->assign('input_annonce_prix',        $this->CreateInputSelectList ($id, 'prix', $this->getPrixListForSelect($application,true) ,array($this->activeSearchFilters[$application]['prix']),1,'',false));
$smarty->assign('input_annonce_surface',    $this->CreateInputSelectList ($id, 'surface', $this->getSurfaceListForSelect(true) ,array($this->activeSearchFilters[$application]['surface']),1,'',false));
$smarty->assign('input_annonce_piece',        $this->CreateInputSelectList ($id, 'piece', $this->getPieceListForSelect(true) ,array($this->activeSearchFilters[$application]['piece']),1,'',false));


$smarty->assign('input_email_alerte',    $this->CreateInputText($id,'email_alerte',    '',30)); // Mon champs pour tester !!
$smarty->assign('submit', $this->CreateInputHidden($id,'display_page',$dest_page ) . $this->CreateInputHidden($id,'application',$application) . $this->CreateInputHidden($id,'page_search',1) . $this->CreateInputSubmit($id, 'submit', $this->Lang('submit')). $this->CreateInputSubmit($id, 'reset', $this->Lang('reset')));
$smarty->assign('end_form', $this->CreateFormEnd());

echo $this->ProcessTemplateFromDatabase('searchfilters_template');

Code :
{if $nb_total_annonces>1}
{$nb_total_annonces} annonces publiées sur notre site<br/>
{/if}
{$start_form}

<table>
  <tr>
    <td>{$input_annonce_secteur}</td>
    <td>{$input_annonce_type}</td>
    <td>{$input_annonce_prix}</td>
    <td>{$input_annonce_surface}</td>
    <td>{$input_annonce_agence}</td>
    <td>{$input_annonce_piece}</td>
    <td>{$input_alerte_email}</td>    
  </tr>
</table>
{$submit}
{$end_form}

Ce code fonctionne car il ne viens pas de moi Tongue j'arrive à récupéré les params, SAUF pour mon champs que je viens d'ajouté, email_alerte ... Alors je me dis qu'il doit y avoir un truc caché quelque part, ou une liste de paramètre autorisé par action, je sais pas ...


Avez vous une idée, vous pro de MS ? Smile

PS : Du côté de la partie admin, j'ai réussi à rajouté un inputtext sans soucis et à le récupéré, mais sur le site en lui même, je sèche la ....

EDIT : Je tiens à préciser qu'en décortiquant un peu le code de MS, la fonction GetModuleParameters() fonctionne bien et retourne un tableau avec mon email et les case coché, alors où est-ce que ces variables disparaissent ?

EDIT 2 : J'ai tout l'impression que c'est la fonction cleanParamHash qui me vire mes paramètres ... car je tombe dans le
Code :
if( !$mapped && !$allow_unknown )
        {
          trigger_error('Parameter '.$key.' is not known by module '.$modulename.' dropped',E_USER_WARNING);
          continue;
        }

Rian

Je m'excuse pour ce sujet, mais je viens de trouver la réponse ...

Il fallait que j'ajoute mon paramètre dans mon module pour qu'il soit reconnu, ainsi pour évité des failles XSS Wink