Input avec name="array[]"
Bonjour,
Je vous explique mon soucis ainsi que le contexte qui est un peu sp�cial.
Dans un formulaire simple pour ajouter un �tablissement. J'ai une section o� l'utilisateur peut renseigner ses diff�rentes formations de son �tablissement. J'ai donc voulu g�rer sa dynamiquement. Donc lorsqu'il rempli les champs de la section formations il y a un faux bouton submit javascript. Qui lorsqu'il est cliqu� ajoute une div en dessous de cette section avec les infos de la formations, puis il peut en ajouter d'autres et ainsi de suite (code ci-dessous).
Lorsqu'il a saisie toutes ses formations et les autres infos de l'�tablissement, je souhaite r�cup�rer toutes les infos ainsi que toutes les formations. Le soucis est ici. Pour afficher les infos des formations j'ai cr�er une div avec tout les �l�ments r�cup�rer ainsi que des champs hidden pour stocker les variables pour r�cup�rer en post dans mon PHP.
J'ai donc voulu y mettre un name="formation[]" pour r�cup�rer un tableau en PHP. Cependant lorsque je fais un var_dump j�obtiens seulement la valeur du dernier champs hidden.
JAVASCRIPT
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| function AjoutFormation(){
getNiveau = document.getElementById('form_niveau');
getCateg = document.getElementById('form_categ_formation');
getFiliere = document.getElementById('form_filiere');
getIntitule = document.getElementById('formation_intitule');
getDesc = document.getElementById('formation_description');
getDuree = document.getElementById('formation_duree');
getfrais = document.getElementById('formation_frais');
getAdmission = document.getElementById('formation_admission');
getInitial = document.getElementById('parcours_1');
getAltern = document.getElementById('parcours_2');
getDist = document.getElementById('parcours_3');
niveau = ''; if(getNiveau.value != 0) niveau = getNiveau.options[getNiveau.selectedIndex].text;
formation = ''; if(getCateg.value != 0) formation =getCateg.options[getCateg.selectedIndex].text;
filiere = ''; if( getFiliere != null && getFiliere.value != 0){
filiere = getFiliere.options[getFiliere.selectedIndex].text;
}
initial = getInitial.checked; if(initial == false){initial = '';}else{initial = ' - Initial'; }
alternance = getAltern.checked; if(alternance == false){alternance = '';}else{alternance = ' - Alternance'; }
distance = getDist.checked; if(distance == false){distance = '';}else{distance = ' - Distance'; }
intitule = getIntitule.value; ;
description = getDesc.value;;
duree = getDuree.value; ;
frais = getfrais.value; ;
admission = getAdmission.value; ;
if(niveau != '' && filiere != '' && formation != '' && (initial != false || alternance != false || distance != false) && intitule != '' && description != ''){
var innerDiv = document.createElement('div');
innerDiv.className = 'formation-block';
innerDiv.id = Math.floor(Math.random() * (999 - 1 + 1)) + 1;
innerDiv.innerHTML = '<p class="title-formation" value="">■ '+niveau+'</p><p class="filiere">→ '+formation+' - '+filiere+initial+alternance+distance+'</p><p id="'+innerDiv.id+'-7" class="intitule-formation">'+intitule+'</p><p id="'+innerDiv.id+'-8" class="description-formation">'+description+'<p><ul><li><strong>Durée</strong>: <span id="'+innerDiv.id+'-9">'+duree+'</span></li><li><strong>Frais</strong>: <span id="'+innerDiv.id+'-10">'+frais+'</span></li><li><strong>Admission</strong>: <span id="'+innerDiv.id+'-11">'+admission+'</span></li></ul><a id="delet-formation" class="button" onclick="SuprFormation('+innerDiv.id+')">Supprimer</a><a id="modif-formation" class="button" onclick="ModifFormation('+innerDiv.id+')">Modifier</a><div class="displaynone"><input id="'+innerDiv.id+'-1" type="hidden" value="'+getNiveau.selectedIndex+'" name="formation[]"/><input id="'+innerDiv.id+'-2" type="hidden" value="'+getCateg.selectedIndex+'" name="formation[]"/><input id="'+innerDiv.id+'-3" type="hidden" value="'+getFiliere.selectedIndex+'" name="formation[]"/><input id="'+innerDiv.id+'-4" type="hidden" value="'+getInitial.checked+'" name="formation[]"/><input id="'+innerDiv.id+'-5" type="hidden" value="'+getAltern.checked+'" name="formation[]"/><input id="'+innerDiv.id+'-6" type="hidden" value="'+getDist.checked+'" name="formation[]"/></div>';
document.getElementById('ajout-formation').appendChild(innerDiv);
getNiveau.selectedIndex = 0;
getCateg.selectedIndex = 0;
getFiliere.selectedIndex = 0;
getInitial.checked= false;
getAltern.checked= false;
getDist.checked= false;
getIntitule.value = ''
getDesc.value = ''
getDuree.value = ''
getfrais.value = ''
getAdmission.value = ''
}
else{
alert('Veuillez remplir tout les champs obligatoires.');
}
} |
R�sultat var_dump
Code:
1 2 3
| 'formation' =>
array (size=1)
0 => string 'false' (length=5) |
Merci d'avance.