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

PHP & Base de données Discussion :

Formulaire avec entrée vocale


Sujet :

PHP & Base de données

  1. #1
    Membre du Club Avatar de IamKanagawa
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2018
    Messages
    114
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2018
    Messages : 114
    Points : 54
    Points
    54
    Par défaut Formulaire avec entrée vocale
    Bonsoir à tous,
    Je n'arrive pas a trouvé mon erreur pour le "text-area" qui me permet d'entrer un texte vocalement avec un API en JavaScript
    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
    <!DOCTYPE html>
    <html lang="fr">
    <head>
        <meta charset="UTF-8">
        <link rel="stylesheet" href="style.css">
        <title>Accueil</title>
    </head>
    <body>
     
    <h1><u>Appréciation</u></h1>
     
    <div class="form_style_1">
     
    <form action="" method="POST" >
     
    <div>
        <label> Saisir le nom de l'eleve :</label><input type="text"  name="nom" placeholder="Nom" >
    </div>   
    <div>
        <label> Saisir appréciation :</label><textarea id="note-textarea" name="textarea" placeholder=" appréciation ..." rows="6"></textarea>
    </div>
        <button id="save-note-btn" name="Valider" title="Save Note">Valider</button>   
        <input type="reset" value="Reset" >
    </form>				
        <button id="start-record-btn" title="Start Recording">Reconnaissance Vocale</button>
        <button id="pause-record-btn" title="Pause Recording">Stop Reconnaissance Vocale</button>
     
    </div>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
     
    		<!-- Web Speech API -->
    		<script src="script.js"></script>
     
    <?php
     
    require 'includes/connecte_bdd.php'; 
    try {
        if( isset ($_POST['Valider'])){
            $nom = $_POST['nom'];
            $appreciation = $_POST['textarea'];
            $req = $bdd->exec("INSERT INTO Appreciation (nom,appreciation_appreciation) VALUES('$nom','$appreciation')");
        }  
    } catch (Exception $e) {
        echo 'Une exception a été lancée. Message d\'erreur : ', $e->getMessage(), "\n";
    }
     
     
    ?>
     
    </body>
    </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
    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
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    try {
        var SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
        var recognition = new SpeechRecognition();
      }
      catch(e) {
        console.error(e);
        $('.no-browser-support').show();
        $('.app').hide();
      }
     
     
      var noteTextarea = $('#note-textarea');
      var instructions = $('#recording-instructions');
      var notesList = $('ul#notes');
     
      var noteContent = '';
     
      var notes = getAllNotes();
      renderNotes(notes);
     
      /*-----------------------------
            Voice Recognition 
      ------------------------------*/
     
      // If false, the recording will stop after a few seconds of silence.
      // When true, the silence period is longer (about 15 seconds),
      // allowing us to keep recording even when the user pauses. 
      recognition.continuous = true;
     
      // This block is called every time the Speech APi captures a line. 
      recognition.onresult = function(event) {
     
        // event is a SpeechRecognitionEvent object.
        // It holds all the lines we have captured so far. 
        // We only need the current one.
        var current = event.resultIndex;
     
        // Get a transcript of what was said.
        var transcript = event.results[current][0].transcript;
     
        // Add the current transcript to the contents of our Note.
        // There is a weird bug on mobile, where everything is repeated twice.
        // There is no official solution so far so we have to handle an edge case.
        var mobileRepeatBug = (current == 1 && transcript == event.results[0][0].transcript);
     
        if(!mobileRepeatBug) {
          noteContent += transcript;
          noteTextarea.val(noteContent);
        }
      };
     
      recognition.onstart = function() { 
        instructions.text('Voice recognition activated. Try speaking into the microphone.');
      }
     
      recognition.onspeechend = function() {
        instructions.text('You were quiet for a while so voice recognition turned itself off.');
      }
     
      recognition.onerror = function(event) {
        if(event.error == 'no-speech') {
          instructions.text('No speech was detected. Try again.');  
        };
      }
     
     
      /*-----------------------------
            App buttons and input 
      ------------------------------*/
     
      $('#start-record-btn').on('click', function(e) {
        if (noteContent.length) {
          noteContent += ' ';
        }
        recognition.start();
      });
     
     
      $('#pause-record-btn').on('click', function(e) {
        recognition.stop();
        instructions.text('Voice recognition paused.');
      });
     
      // Sync the text inside the text area with the noteContent variable.
      noteTextarea.on('input', function() {
        noteContent = $(this).val();
      })
     
      $('#save-note-btn').on('click', function(e) {
        recognition.stop();
     
        if(!noteContent.length) {
          instructions.text('Could not save empty note. Please add a message to your note.');
        }
        else {
          // Save note to localStorage.
          // The key is the dateTime with seconds, the value is the content of the note.
          saveNote(new Date().toLocaleString(), noteContent);
     
          // Reset variables and update UI.
          noteContent = '';
          renderNotes(getAllNotes());
          noteTextarea.val('');
          instructions.text('Note saved successfully.');
        }
     
      })
     
     
      notesList.on('click', function(e) {
        e.preventDefault();
        var target = $(e.target);
     
        // Listen to the selected note.
        if(target.hasClass('listen-note')) {
          var content = target.closest('.note').find('.content').text();
          readOutLoud(content);
        }
     
        // Delete note.
        if(target.hasClass('delete-note')) {
          var dateTime = target.siblings('.date').text();  
          deleteNote(dateTime);
          target.closest('.note').remove();
        }
      });
     
     
     
      /*-----------------------------
            Speech Synthesis 
      ------------------------------*/
     
      function readOutLoud(message) {
          var speech = new SpeechSynthesisUtterance();
     
        // Set the text and voice attributes.
          speech.text = message;
          speech.volume = 1;
          speech.rate = 1;
          speech.pitch = 1;
     
          window.speechSynthesis.speak(speech);
      }
     
     
     
      /*-----------------------------
            Helper Functions 
      ------------------------------*/
     
      function renderNotes(notes) {
        var html = '';
        if(notes.length) {
          notes.forEach(function(note) {
            html+= `<li class="note">
              <p class="header">
                <span class="date">${note.date}</span>
                <a href="#" class="listen-note" title="Listen to Note">Listen to Note</a>
                <a href="#" class="delete-note" title="Delete">Delete</a>
              </p>
              <p class="content">${note.content}</p>
            </li>`;    
          });
        }
        else {
          html = '<li><p class="content">You don\'t have any notes yet.</p></li>';
        }
        notesList.html(html);
      }
     
     
      function saveNote(dateTime, content) {
        localStorage.setItem('note-' + dateTime, content);
      }
     
     
      function getAllNotes() {
        var notes = [];
        var key;
        for (var i = 0; i < localStorage.length; i++) {
          key = localStorage.key(i);
     
          if(key.substring(0,5) == 'note-') {
            notes.push({
              date: key.replace('note-',''),
              content: localStorage.getItem(localStorage.key(i))
            });
          } 
        }
        return notes;
      }
     
     
      function deleteNote(dateTime) {
        localStorage.removeItem('note-' + dateTime); 
      }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    <?php
     
    $server = 'localhost';
    $database = 'Appreciation_bdd';
    $username = 'root';
    $password = 'root';
    try{
        $bdd = new PDO('mysql:host='.$server.';dbname='.$database.';charset=utf8', ''.$username.'', ''.$password.'');
    }
        catch (PDOException $e) {
          throw new InvalidArgumentException('Erreur connexion à la base de données : '.$e->getMessage());
          exit;
       }
        ?>
    Il faut se tromper dans la vie, pour apprendre et s'améliorer.

    Etudiant BTS-SIO option SLAM

  2. #2
    Modératrice
    Avatar de Celira
    Femme Profil pro
    Développeuse PHP/Java
    Inscrit en
    Avril 2007
    Messages
    8 633
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 39
    Localisation : France

    Informations professionnelles :
    Activité : Développeuse PHP/Java
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2007
    Messages : 8 633
    Points : 16 372
    Points
    16 372
    Par défaut
    Et quel est le problème exactement ? le text-area ne se remplit pas ? il ne s'enregistre pas ?
    Modératrice PHP
    Aucun navigateur ne propose d'extension boule-de-cristal : postez votre code et vos messages d'erreurs. (Rappel : "ça ne marche pas" n'est pas un message d'erreur)
    Cherchez un peu avant poser votre question : Cours et Tutoriels PHP - FAQ PHP - PDO une soupe et au lit !.

    Affichez votre code en couleurs : [CODE=php][/CODE] (bouton # de l'éditeur) et [C=php][/C]

  3. #3
    Membre du Club Avatar de IamKanagawa
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2018
    Messages
    114
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2018
    Messages : 114
    Points : 54
    Points
    54
    Par défaut
    Oui le nom s'envoie mais le text area non
    Il faut se tromper dans la vie, pour apprendre et s'améliorer.

    Etudiant BTS-SIO option SLAM

Discussions similaires

  1. Validation de formulaire avec entrée : envoi du premier bouton
    Par Difré91 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 5
    Dernier message: 13/06/2012, 10h25
  2. Valider formulaire contenant deux listes avec Entrée
    Par lili2704 dans le forum Struts 1
    Réponses: 8
    Dernier message: 07/08/2007, 18h00
  3. [MySQL] PHP formulaire avec heure en entrée
    Par oldhag dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 28/03/2006, 17h12
  4. PB controle formulaire avec tableau à double entrées
    Par Poutchou dans le forum Général JavaScript
    Réponses: 36
    Dernier message: 23/03/2006, 14h37

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