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 55
| var compteur = 0;
$("#Ajouter").click(function(){
var idOeuvres = $("#id_oeuvres").val();
var nombrePhotos = $("#nb_photos").val();
inputFiles = '';
inputFiles+= '<span id="erreur"></span>';
inputFiles+= '<form id="formPhotos" enctype="multipart/form-data" action="gestionPhotos.php?mode=validerAjouter&id_oeuvres='+idOeuvres+'" method="post">';
compteur++;
if (compteur<=1)
{
for (var inc=1; inc<=nombrePhotos; inc++)
{
inputFiles+= '<p>Photo '+inc+' : <input id="photos_'+inc+'" type="file" name="photo_'+inc+'"/><span id="erreur_photo_'+inc+'"></span></p>';
}
if (compteur>0)
{
// inputFiles+= '<input type="hidden" name="nb_photos" value="'+nombrePhotos+'"/>';
inputFiles+= '<p><input type="submit" id="ajouterPhotos" value="Ajouter"/></p>';
}
inputFiles+= '</form>';
}
$('#inputs_files').append(inputFiles);
// un fois le formulaire d'ajout des photos affichée,
// on vérifie du formulaire.
$("#formPhotos").bind("submit", function () {
var valide = true;
var message = 'Veuillez remplir ce champ !';
var nombrePhotos = $("#nb_photos").val();
// vérification pour chaque champ !
for (var cpt=1; cpt<=nombrePhotos; cpt++) {
if ($("#photos_"+cpt).val()=="") {
$("#erreur_photo_"+cpt).parent("p").css("color", "red");
$("#erreur_photo_"+cpt).parent("p").append(message);
valide = false;
}
}
return valide;
});
}); |
Partager