Bonjour les experts

Je suis pseudo débutant, j'ai grace à vous découvert certaines choses sympa en AJAX et formulaire. J'utilise donc aujourd'hui ces technique pour gerer une renouvellement de mot de passe sur mon site. Ma problématique est simple:
Lorsque l'utilisateur a oublié son mot de passe, il clique sur un lien et arrive sur un formulaire multistep.

step 1: il saisit son nom et son numéro de téléphone. C'est informations par AJAX sont contrôlées dans la base de donnée.

step 2: - Si les données saisies sont bien dans la base de donnée, j'affiche à ce step la question sécrète validé par l'utilisateur lors de son inscription et un champs de saisie pour la réponse à cette question.
- Si les données saisies ne son pas correctes je souhaite rester au step 1 et afficher un message d’alerte

step 3: Je fais le même contrôle avec la BDD pour m'assurer que la réponse à la question sécrète saisie au step 2 est correcte. sinon je reste au step 2 avec un message d'alerte. Si correcte, alors j'offre la possibilité de renouveler son mot de passe et le submit met à jour la base de donnée.

Voici ce que je souhaite faire mais impossible d'y arriver. Tout marche bien quand les données saisies sont juste. Dès que les saisie du step 1 sont fausse, plus rien de marche.

Mon code HTML
Code html : 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
						<form action="connexion.php" method="post" id="newpassword" name="newpassword">
	<div style="text-align:center;">
		<span class="step"></span>
		<span class="step"></span>
		<span class="step"></span>
	</div>
 
	<div class="row tab px-2 py-3">
		<div class="col">
			<p><small>Tous les champs sont obligatoires</small></p>
			<label class="control-label" for="numero">Nom et prénom*</label>
			<div class="input-group pb-3">
				<div class="input-group-prepend">
					<span class="input-group-text" >
						<i class="fa fa-user" aria-hidden="true"></i>
					</span>
				</div>														
				<input class="form-control" data-parsley-group="block0" type="text" id="username" 
				name="username"> 											
			</div>
 
			<label class="control-label" for="numero">Téléphone*</label>
			<div class="input-group pb-3">
				<div class="input-group-prepend">
					<span class="input-group-text" >
						<i class="fa fa-phone-volume" aria-hidden="true"></i>
					</span>
				</div>														
				<input class="form-control" data-parsley-group="block0" type="text" id="user" name="user"
				pattern="[0-9]{8}" maxlength="8" onkeypress="phonenumber(event); return false;" 
				onchange="return miphone()"> 											
			</div>
		</div>
	</div>
	<div class="row tab px-2 py-3">
		<div class="col">
			<label class="control-label" for="numero"><strong id="question"></strong> </label>
			<div class="input-group pb-3">
				<div class="input-group-prepend">
					<span class="input-group-text" >
						<i class="fa fa-user" aria-hidden="true"></i>
					</span>
				</div>										
				<input class="form-control" data-parsley-group="block0" type="text" id="reponse" 
				name="reponse" onchange="return mireponse()"> 	
			</div>
		</div>
	</div>
	<div class="row tab px-2 py-3">
		<input class="form-control" data-parsley-group="block0" type="iden" id="reponse">								
		<span id="reponse"></span>
		<div class="col">
			<label class="control-label" for="numero">Mot de passe*</label>
			<div class="input-group pb-2">
				<div class="input-group-prepend">
					<span class="input-group-text" >
						<i class="fa fa-key" aria-hidden="true"></i>
					</span>
				</div>														
				<input class="form-control" data-parsley-group="block0" type="password" id="password" 
				name="password"> 											
			</div>								
		</div>
	</div>
	<div class="row d-flex justify-content-around">
		<div class="col d-flex justify-content-center">
			<button class="btn btn-outline-rounded btn-primary px-5 mb-3 mx-3" type="button" id="prevBtn" onclick="nextPrev(-1)">Retour</button>
 
			<button class="btn btn-outline-rounded btn-primary px-5 mb-3 mx-3" type="button" id="nextBtn" onclick="nextPrev(1)">Suivant</button>
		</div>
	</div>
</form>
 
 
 
<script>
                function phonenumber(event) {                           
                        var keyCode = event.which ? event.which : event.keyCode;
                        var touche = String.fromCharCode(keyCode);
                                        
                        var champ = document.getElementById('phone');
                                        
                        var caracteres = '0123456789';
                                        
                        if(caracteres.indexOf(touche) >= 0) {
                                champ.value += touche;
                        }
                }
 
 
// Multi-Step Form
var currentTab = 0; // Current tab is set to be the first tab (0)
showTab(currentTab); // Display the crurrent tab
 
function showTab(n) {
  // This function will display the specified tab of the form...
  var x = document.getElementsByClassName("tab");
  x[n].style.display = "block";
  //... and fix the Previous/Next buttons:
  if (n == 0) {
    document.getElementById("prevBtn").style.display = "none";
  } else {
    document.getElementById("prevBtn").style.display = "inline";
  }
  if (n == (x.length - 1)) {
    document.getElementById("nextBtn").innerHTML = "Commander";
  } else {
    document.getElementById("nextBtn").innerHTML = "Suivant";
  }
  
  if (n == (x.length - 1)) {
    document.getElementById("nextBtn").style.display = "none";
  } else {
        document.getElementById("nextBtn").style.display = "inline";
  }
  //... and run a function that will display the correct step indicator:
  fixStepIndicator(n)
}
 
function nextPrev(n) {
  // This function will figure out which tab to display
  var x = document.getElementsByClassName("tab");
  // Exit the function if any field in the current tab is invalid:
  if (n == 1 && !validateForm()) return false;
  // Hide the current tab:
  x[currentTab].style.display = "none";
  // Increase or decrease the current tab by 1:
  currentTab = currentTab + n;
  // if you have reached the end of the form...
  if (currentTab >= x.length) {
    // ... the form gets submitted:
    document.getElementById("newpassword").submit();
    return false;
  }
  // Otherwise, display the correct tab:
  showTab(currentTab);
}
 
function validateForm() {
  // This function deals with validation of the form fields
  var x, y, i, valid = true;
  var todayDate = new Date();
  todayDate = formatDate(todayDate);
 
  x = document.getElementsByClassName("tab");
  y = x[currentTab].getElementsByTagName("input");
  z = x[currentTab].getElementsByTagName("select");
  // A loop that checks every input field in the current tab:
  for (i = 0; i < y.length; i++) {
    // If a field is empty...
    if (y[i].value == "") {
      // add an "invalid" class to the field:
      y[i].className += " invalid";
      // and set the current valid status to false:
      valid = false;
    }
 
 
        if (y[i].type == "date" && y[i].value > todayDate) {
      // add an "invalid" class to the field:
      y[i].className += " invalid";
      // and set the current valid status to false:
      valid = false;
    }
 
  }
  // A loop that checks every select field in the current tab:
  for (i = 0; i < z.length; i++) {
    // If a field is empty...
    if (z[i].value == "") {
      // add an "invalid" class to the field:
      z[i].className += " invalid";
      // and set the current valid status to false:
      valid = false;
    }
  }
  // If the valid status is true, mark the step as finished and valid:
  if (valid) {
    document.getElementsByClassName("step")[currentTab].className += " finish";
  }
  return valid; // return the valid status
}
 
 
function fixStepIndicator(n) {
  // This function removes the "active" class of all steps...
  var i, x = document.getElementsByClassName("step");
  for (i = 0; i < x.length; i++) {
    x[i].className = x[i].className.replace(" active", "");
  }
  //... and adds the "active" class on the current step:
  x[n].className += " active";
}
                
        </script>

A partir de ce code HTML, je fais appel à mon AJAX par le fichier scriptphone.php

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
<script>
    function miphone() {
        var miphone = document.newpassword;
        var dataString = $(miphone).serialize();
        $.ajax({
            type: 'POST',
            url: '../shared/service/phone.php',
            data: dataString,
			dataType:"json",
 
			success: function (data) {
				if (question  == '0') {
                 	document.getElementById("reponse").innerHTML = 'Attention : données saisie incorrectes' ;
                } else {				
					$('#question').html(data.question);
				}
 
			}
 
		})			
				return false;
    }
 
    function mireponse() {
        var mireponse = document.newpassword;
        var dataString = $(mireponse).serialize();
        $.ajax({
            type: 'POST',
            url: '../shared/service/reponse.php',
            data: dataString,
			dataType:"json",
 
			success: function (data) {
 
                $('#reponse').html(data.reponse);
 
			}
 
		})			
				return false;
    }
</script>
Et le fichier PHP phone.php que j'utilise pour le contrôle dans la base de donnée.

Code PHP : 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
<?php
	if (session_status() == PHP_SESSION_NONE) {
		session_start();
 
	}
 
	include('../../shared/service/globale.php');
	include('../../shared/service/paramauto.php');
	include('../../shared/service/functionauto.php');
	include('../../shared/service/connect.php');
 
	global $phone;
	global $question;
	global $reponse;
 
 
	if((isset($_POST['username']) && !empty($_POST['username']))
	&& (isset($_POST['user']) && !empty($_POST['user'])))	
	{
		$nomprenom = strtoupper($_POST['username']);
		$phone = $_POST['user'];
 
		$req = $db->prepare('SELECT count(*) as nbuser FROM assures WHERE phone=? and nomprenom=?');
		$req->execute(array($phone, $nomprenom));
		$count = $req->fetch(PDO::FETCH_ASSOC);
		If ($count['nbuser']>0) {
 
			$sql="SELECT * FROM assures WHERE phone=? and nomprenom=?";
			$select= $db->prepare($sql);
			$select->execute(array($phone, $nomprenom));
			while($m = $select->fetch(PDO::FETCH_OBJ)) {
				$question = $m->question;
				if ($question == '1') {
					$question = 'Votre matière préférée à l\'école';
				} elseif ($question == '2'){
					$question = 'La marque de votre première voiture';
				} elseif ($question == '3') {
					$question = 'Votre ville de naissance';
				}	
			}
 
 
 
		} else {
			$question = '0';			
		}
 
		echo json_encode([
			"question"=>$question,
 
		]);
 
	}

Pourriez-vous me donner un coup de main s'il vous plait? Je n'ai vraiment pas le compétence pour inventer du code mais j'adapte toujours vos préconisations à mes besoins.
Je vous remercie d'avance

Cordialement.