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

Langage PHP Discussion :

[PHP-JS] Comment rendre la saisie obligatoire ?


Sujet :

Langage PHP

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    62
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 62
    Points : 30
    Points
    30
    Par défaut [PHP-JS] Comment rendre la saisie obligatoire ?
    Bonjour,

    J'ai développé une fiche d'inscription mais je ne sais pas comment rendre certains champs tels que (Nom, Prénom et Email) obligatoires
    Comment puis je tester dans cette fiche, la non nullité de ces 3 champs ?
    si ces 3 champs ne sont pas remplis, je boucle dans la fiche en forçant un focus sur le champ non saisi.
    merci de votre aide.

    Voici le code de ma fiche d'inscription

    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
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
     
    <?php
    //init des variables 
    if (!isset($HTTP_POST_VARS['BSubmit'])) $HTTP_POST_VARS['BSubmit']="";
    if (!isset($erreurlog)) $erreurlog=0;
     
     
     
    if ($HTTP_POST_VARS['BSubmit']=="Envoyer") {
    	$whbh_mail_to="gcharniere@yahoo.fr";
    	$whbh_mail_text = $_POST['RBMrMmeMelle'] . " " . $_POST['CNom'] . " " . $_POST['CPrenom'] . "\n" .
    	$_POST['CAddr1'] . "\n" .
    	$_POST['CAddr2'] . "\n" .
    	$_POST['CCode'] . " " . $_POST['CVille'] . "\n"  .
    	$_POST['CComment'] . "\n" .
    	"\n" .
    	$_POST['CEmail'] . "\n" ;
    	$whbh_mail_reply= "xxxxx@reply.com";
    	$whbh_mail_from="MonSite@yahoo.com";
    	$whbh_mail_sujet= "Demande d'inscription"; 
    	$whbh_date = date("D, j M Y H:i:s -0600"); 	// avec offset horaire
     
    	$entetemail  = "From: $whbh_mail_from \n"; 	// Adresse expéditeur
    	$entetemail .= "Cc: \n";  			// Carbon Copy
    	$entetemail .= "Bcc: $whbh_mail_from \n"; 			// Copies cachées
    	$entetemail .= "Reply-To: $whbh_mail_from \n";  // Adresse de retour
    	$entetemail .= "X-Mailer: PHP/" . phpversion() . "\n" ;
    	$entetemail .= "Date: $whbh_date"; 
    	mail($whbh_mail_to, $whbh_mail_sujet, $whbh_mail_text, $entetemail);
    	header("Location: mainframe_accueil.php");
    	exit();
    	}
    ?>
     
     
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
     
    <link href="blstyle.css" rel="stylesheet" type="text/css">
    <style type="text/css">
    <!--
    body {
    	background-image: url(Images/Nature%20Bkgrd.jpg);
    }
    -->
    </style></head>
    <body class="sub">
    <form name="form1" method="post" action="">
      <div align="left"></div>
      <table width="85%" border="0" cellpadding="8">
          <tr> 
            <td colspan="3" class="HeaderColor"> <h4 align="center"><span style="mso-bidi-font-size: 12.0pt"><span class="MF_Style_2"><font color="#007FFF" face="Comic Sans MS" size="3">Formulaire d'inscription</font></span></span></h4></td>
          </tr>
     
          <tr style="vertical-align: top"> 
            <td style="text-align: right" class="Texte">
              Civilit&eacute;</td>
            <td colspan="2">   <pre class="Texte"><label for="civilite"><span class="Texte_Gras">Monsieur</span></label>   <span class="Texte_Gras"><input name="RBMrMmeMelle" type="radio" id="monsieur" value="Monsieur" checked>         <label for="madame"> Madame</label>   <input name="RBMrMmeMelle" type="radio" id="madame"  value="Madame">          <label for="mademoiselle">Mademoiselle </label>   <input name="RBMrMmeMelle" type="radio" id="mademoiselle"  value="Mademoiselle">     </span></pre>        </td>
          </tr>
     
          <tr style="vertical-align: top"> 
            <td width="23%" nowrap class="LabelColor" style="text-align: right"><label for="username" class="Texte">
              Nom et Pr&eacute;nom </label></td>
            <td class="TitleColor"> <input name="CNom" type="text" class="Texte_Gras" id="IdNom" value="Nom" size="30"></td>
            <td class="TitleColor"> <input name="CPrenom" type="text" class="Texte_Gras" id="IdPrenom" value="Pr&eacute;nom" size="30"></td>
          </tr>
     
          <tr style="vertical-align: top"> 
            <td style="text-align: right" class="LabelColor"><label for="addr1" class="Texte">
              Adresse 1 </label></td>
            <td colspan="2" class="TitleColor">  <input name="CAddr1" type="text" class="Texte_Gras" id="IdAddr1" value="Adresse 1&egrave;re partie" size="70"></td>
          </tr>
     
          <tr style="vertical-align: top"> 
            <td style="text-align: right" class="LabelColor"><label for="addr2" class="Texte">
              Adresse 2 </label></td>
            <td colspan="2" class="TitleColor">  <input name="CAddr2" type="text" class="Texte_Gras" id="IdAddr2" value="Adresse 2&egrave;me partie" size="70">          </td>
          </tr>
     
          <tr style="vertical-align: top"> 
            <td height="33" class="Texte" style="text-align: right">
              Code Postal et Ville </td>
            <td width="31%" class="TitleColor">  <label for="codepostal"></label>   <input name="CCode"  type="text" class="Texte_Gras" id="IdCode" value="Code" size="6" maxlength="5">    </td>
            <td width="46%" class="TitleColor">  <label for="ville"></label>    <input name="CVille" type="text" class="Texte_Gras" id="IdVille" value="Ville" size="30">       </td>
          </tr>
     
          <tr style="vertical-align: top"> 
            <td height="33" class="LabelColor" style="text-align: right"><label for="email" class="Texte">
            Email</label></td>
            <td colspan="2" class="TitleColor">  <input name="CEmail" type="text" class="Texte_Gras" id="IdEmail" value="Email" size="50">          </td>
          </tr>
     
          <tr style="vertical-align: top">
            <td height="33" class="LabelColor" style="text-align: right"><label for="comment" class="Texte"> Observations </label></td>
            <td colspan="2" class="TitleColor">
              <textarea name="CComment" cols="70" rows="4" wrap="VIRTUAL" class="Texte_Gras" id="IdEmail">Vos Observations</textarea>
            </td>
          </tr>
     
          <tr style="vertical-align: top"> 
            <td colspan="3">  <pre class="Texte">Versement d'acompte :    Oui <input name="RBOuiNon" type="radio" id="yes1"  value="Oui" checked>        N<label for="no1">on</label><input type="radio" id="no1" name="RBOuiNon" value="Non">    </pre>          </td>
          </tr>
     
          <tr style="vertical-align: top" class="FooterColor">
          <td height="36" colspan="3"><div align="center">
            <input name="BSubmit" type="submit" class="Texte_Gras" id="BSubmit" value="Envoyer">
          </div></td>
        </tr>
     
    </table>
    </form>
    </body>
    </html>

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    1 221
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 1 221
    Points : 472
    Points
    472
    Par défaut
    if(!empty(champ1) AND !empty(champ2) AND !emtpy(champ3))
    {passer à la suite;}
    else {retour à la page d'inscription avec message "les trois champs sont obligatoires";}

    C'est ça ou c'était quelque chose de plus complexe ?
    C'est pas parce que j'ai tort que vous avez raison.

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    62
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 62
    Points : 30
    Points
    30
    Par défaut
    Plutot comme cela
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    if (!empty(champ1)) then set.focus (champ1)
    if (!empty(champ2)) then set.focus (champ2)
    if (!empty(champ3)) then set.focus (champ3)
    Merci

  4. #4
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    62
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 62
    Points : 30
    Points
    30
    Par défaut
    Apres, il y aura

    if (!empty(champ1) AND !empty(champ2) AND !emtpy(champ3))
    {passer à la suite;}
    else {retour à la page d'inscription avec message "les trois champs sont obligatoires";}



    Merci beaucoup :o

  5. #5
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    62
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 62
    Points : 30
    Points
    30
    Par défaut
    Quelqu'un pourrait m'aider ?

  6. #6
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    1 027
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 1 027
    Points : 1 164
    Points
    1 164
    Par défaut
    Une solution comme une autre.

    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
    $jsError = "";
     
    if ($HTTP_POST_VARS['BSubmit']=="Envoyer") { 
     
    if($_POST['CNom'] =="")
    {
    $jsError .= "document.getElementById('IdNom').focus();\ndocument.getElementById('IdNom').style.borderColor='red';\ndocument.getElementById('IdNom').style.borderWidth='1px';\ndocument.getElementById('IdNom').style.borderStyle='solid';";
    }
    if($_POST['CPrenom'] =="")
    {
    $jsError .= "document.getElementById('IdPrenom').focus();\ndocument.getElementById('IdPrenom').style.borderColor='red';\ndocument.getElementById('IdPrenom').style.borderWidth='1px';\ndocument.getElementById('IdPrenom').style.borderStyle='solid';";
    }
     
    if( $jserror != "")
    {
    $whbh_mail_to="gcharniere@yahoo.fr"; 
       $whbh_mail_text = $_POST['RBMrMmeMelle'] . " " . $_POST['CNom'] . " " . $_POST['CPrenom'] . "\n" . 
       $_POST['CAddr1'] . "\n" . 
       $_POST['CAddr2'] . "\n" . 
       $_POST['CCode'] . " " . $_POST['CVille'] . "\n"  . 
       $_POST['CComment'] . "\n" . 
       "\n" . 
       $_POST['CEmail'] . "\n" ; 
       $whbh_mail_reply= "xxxxx@reply.com"; 
       $whbh_mail_from="MonSite@yahoo.com"; 
       $whbh_mail_sujet= "Demande d'inscription"; 
       $whbh_date = date("D, j M Y H:i:s -0600");    // avec offset horaire 
     
       $entetemail  = "From: $whbh_mail_from \n";    // Adresse expéditeur 
       $entetemail .= "Cc: \n";           // Carbon Copy 
       $entetemail .= "Bcc: $whbh_mail_from \n";          // Copies cachées 
       $entetemail .= "Reply-To: $whbh_mail_from \n";  // Adresse de retour 
       $entetemail .= "X-Mailer: PHP/" . phpversion() . "\n" ; 
       $entetemail .= "Date: $whbh_date"; 
       mail($whbh_mail_to, $whbh_mail_sujet, $whbh_mail_text, $entetemail); 
       header("Location: mainframe_accueil.php"); 
       exit(); 
    }
       } 
    ?> 
     
    <html> 
    <head> 
    <title>Untitled Document</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
     
    <link href="blstyle.css" rel="stylesheet" type="text/css"> 
    <style type="text/css"> 
    <!-- 
    body { 
       background-image: url(Images/Nature%20Bkgrd.jpg); 
    } 
    --> 
    </style>
     
    <script langage="javascript" type="text/javascript'>
    window.onload =function()
    {
    <? echo $jserror; ?>
    }
    </script>
     
    </head>

    Inspire t'en, ce n'est qu'une ébauche il manque plein de chose notemment dans la protection des données envoyées dans la requete.

    bye

  7. #7
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    62
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 62
    Points : 30
    Points
    30
    Par défaut
    N'y a t-il vraiment pas moyen de faire en Php ?
    car le javascript, je ne connais pas trop ...
    je m'excuse ...

  8. #8
    Membre expérimenté
    Avatar de Linaa
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    987
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 987
    Points : 1 309
    Points
    1 309
    Par défaut
    Pour mettre le focus, le JavaScript est la seule possibilité !
    Et pour cela, tu as juste à savoir que
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    document.getElementById('champ').focus();
    sert à donner le focus à un champ ayant un id="champ"

  9. #9
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    62
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 62
    Points : 30
    Points
    30
    Par défaut
    Je peux m'en passer du setfocus
    Pourriez vous m'expliquer comment faire en pur PHP avec les isset et les $_post, j'ai peur de faire du Javascript car je ne comprends pas du tout ce langage. merci de votre compréhension.

  10. #10
    Membre expérimenté
    Avatar de Linaa
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    987
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2005
    Messages : 987
    Points : 1 309
    Points
    1 309
    Par défaut
    Citation Envoyé par psychoBob
    if (!empty(champ1) AND !empty(champ2) AND !emtpy(champ3))
    {passer à la suite;}
    else {retour à la page d'inscription avec message "les trois champs sont obligatoires";}
    T'as essayé ça au moins ?! C'est exactement ce que tu veux...

  11. #11
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    62
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 62
    Points : 30
    Points
    30
    Par défaut
    oui, c'est bien cela que je voulais
    avec les isset et les $_post
    merci d'avance

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [AC-2007] Comment rendre la saisie dans un champ non obligatoir
    Par ellyam dans le forum Access
    Réponses: 1
    Dernier message: 23/05/2012, 12h35
  2. [WD15] Comment rendre la saisie dans un champ non obligatoir
    Par ellyam dans le forum WinDev
    Réponses: 7
    Dernier message: 23/05/2012, 12h28
  3. Réponses: 4
    Dernier message: 10/08/2010, 23h40
  4. rendre une saisie obligatoire dans un formulaire
    Par heteroclite dans le forum Général JavaScript
    Réponses: 9
    Dernier message: 17/09/2006, 23h26
  5. [PHP-JS] comment vérifier la saisie des champs ?
    Par tigzirt dans le forum Langage
    Réponses: 4
    Dernier message: 27/06/2006, 17h26

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