IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

HTML Discussion :

Ne pas envoyer le formulaire si champs est vide.


Sujet :

HTML

  1. #1
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mars 2005
    Messages : 2
    Points : 1
    Points
    1
    Par défaut Ne pas envoyer le formulaire si champs est vide.
    Bonjour à tous,
    Je suis débutant et j'ai un gros problème.
    J'ai cré un site où on peu remplir un formulaire qui m'envoie donc le résultat sur une base SQL.
    Le problème c'est qu'il ya des rigolos qui ne remplissent pas le formulaire et me l'envoie vide grrrr comment pourrais-je eviter cela --> donc il faudrait que lorsque un champs n'est pas remplie dans mon formulaire html , il y ai un message erreur
    Merci pour votre aide précieux.
    voici mon formulaire html

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    <html>
     
    <head>
    <title>Envoi de fichiers </title>
    <base target="_self"></head>
     
    <body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
    <p align=center style='text-align:center'>&nbsp;</p>
     
    <form method="post" action="ajout_tv"> 
        <p align="center">&nbsp;</p>
    <table width="518" border="1" cellspacing="0" align="center" bgcolor="#ECE8DE" bordercolordark="white" bordercolorlight="black">
    <tr>
    <td width="87" height="26">
                    <p align="center"><b><font size="2">Déscription</font></b></td>
    <td width="431" height="26">
                    <B><input type="text" name="description" maxlength="100" size="40"></B>
    </td>
    </tr>
    <tr>
    <td width="87" height="26">
                    <p align="center"><b><font size="2">Prix</font></b></td>
    <td width="431" height="26">
                    <B><input type="text" name="prix" maxlength="14" size="40"></B>
    </td>
    </tr>
    <tr>
    <td width="87">
                    <p align="center"><b><font size="2">Prix fixe</font></b></p>
    </td>
    <td width="431">
                    <select name="prixfixe" size="1">
                    <option value="Oui">Oui</option>
                    <option>Non</option>
                    <option value="à discuter">à discuter</option>
                    </select>
    </td>
    </tr>
    <tr>
    <td width="87">
                    <p align="center"><b><font size="2">Tel</font></b></p>
    </td>
    <td width="431">
                    <B><input type="text" name="tel" maxlength="20" size="40"></B>
    </td>
    </tr>
            <tr>
    <td width="87">
                    <p align="center"><b><font size="2">émail</font></b></p>
    </td>
    <td width="431">
                    <B><input type="text" name="email" maxlength="40" size="40"></B>
    </td>
            </tr>
    <tr>
    <td width="87">
                    <p align="center"><b><font size="2">&nbsp;</font></b></td>
    <td width="431">
                    <p align="center"><B><input type="submit" name="Submit" value="Envoyer"></B>
    </td>
    </tr>
    </table>
    </form>
    </body>
     
    </html>

  2. #2
    Membre éclairé Avatar de Sheriff
    Inscrit en
    Octobre 2004
    Messages
    608
    Détails du profil
    Informations forums :
    Inscription : Octobre 2004
    Messages : 608
    Points : 718
    Points
    718
    Par défaut
    salut.
    tu fais
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <form unsubmit="return verifier()"...>
    dans la fonction tu fais
    Code Javascript : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    function verifier(){
    var champs_vides=0;
    champs_vides+=(document.mon_formulaire.mon_champ.value.length==0);
    ...
    ...
    if (champs_vides) alert("il existe encore des champs vides");
    return champs_vides;
    }
    tu peux aussi récupérer tous les champs et effectuer les tests dans une boucle ; en tous cas c'est cette voie que je propose...
    @+
    Que votre situation soit bonne ou mauvaise, cela va changer...

  3. #3
    Modérateur
    Avatar de Bisûnûrs
    Profil pro
    Développeur Web
    Inscrit en
    Janvier 2004
    Messages
    9 868
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Janvier 2004
    Messages : 9 868
    Points : 16 258
    Points
    16 258

  4. #4
    Nouveau Candidat au Club
    Profil pro
    Inscrit en
    Mars 2005
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Mars 2005
    Messages : 2
    Points : 1
    Points
    1
    Par défaut je suis vraiment un débutant
    cela donne ca alors ???

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    <html>
     
    <head>
    <title>Envoi de fichiers </title>
    <base target="_self"></head>
     
    <body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
    <p align=center style='text-align:center'>&nbsp;</p>
     
    <form method="post" action="ajout_tv"> 
        <p align="center">&nbsp;</p>
    <table width="518" border="1" cellspacing="0" align="center" bgcolor="#ECE8DE" bordercolordark="white" bordercolorlight="black">
    <tr>
    <td width="87" height="26">
                    <p align="center"><B><font size="2">Déscription</font></B></td>
    <td width="431" height="26">
                    <B><input type="text" name="description" maxlength="100" size="40"></B>
    </td>
    </tr>
    <tr>
    <td width="87" height="26">
                    <p align="center"><B><font size="2">Prix</font></B></td>
    <td width="431" height="26">
                    <B><input type="text" name="prix" maxlength="14" size="40"></B>
    </td>
    </tr>
    <tr>
    <td width="87">
                    <p align="center"><B><font size="2">Prix fixe</font></B></p>
    </td>
    <td width="431">
                    <select name="prixfixe" size="1">
                    <option value="Oui">Oui</option>
                    <option>Non</option>
                    <option value="à discuter">à discuter</option>
                    </select>
    </td>
    </tr>
    <tr>
    <td width="87">
                    <p align="center"><B><font size="2">Tel</font></B></p>
    </td>
    <td width="431">
                    <B><input type="text" name="tel" maxlength="20" size="40"></B>
    </td>
    </tr>
            <tr>
    <td width="87">
                    <p align="center"><B><font size="2">émail</font></B></p>
    </td>
    <td width="431">
                    <B><input type="text" name="email" maxlength="40" size="40"></B>
    </td>
            </tr>
    <tr>
    <td width="87">
                    <p align="center"><B><font size="2">&nbsp;</font></B></td>
    <td width="431">
                    <p align="center"><B><input type="submit" name="Submit" value="Envoyer"></B>
    </td>
    </tr>
    </table>
    </form>
    <script language="JavaScript">
    <!-- Beginning of JavaScript -
     
    function verifier(){
    var champs_vides=0;
    champs_vides+=(document.mon_formulaire.mon_champ.value.length==0);
    if (champs_vides) alert("il existe encore des champs vides");
    return champs_vides;
    }
    // - End of JavaScript - -->
    </script>
     
    </body>
     
    </html>

Discussions similaires

  1. Réponses: 4
    Dernier message: 25/06/2013, 13h25
  2. [CKEditor] Tester si le champ est vide avant envoi du formulaire
    Par Xrris dans le forum Bibliothèques & Frameworks
    Réponses: 1
    Dernier message: 17/04/2009, 11h59
  3. [MySQL] Verifier si un champ est vide et on ne l'affiche pas
    Par cysedbs dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 12/12/2007, 16h31
  4. vérifier qu'un champ est vide dans un formulaire
    Par dr_feelgood dans le forum IHM
    Réponses: 3
    Dernier message: 08/06/2007, 07h21
  5. Réponses: 1
    Dernier message: 20/03/2006, 13h30

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo