I would like the user to take into account in the form that the numbers are entered with periods and not with commas and I have a problem: the error message is displayed when entering a decimal number or a number with a period.
So how could I complete the formula so that the message is displayed only when the user puts a comma?
first I used this:
if (in_array($_SESSION['profil'], ['Consultation - Lecture seule', 'Consultation nationale', 'Pilote Investissement M2IO']) || ($_SESSION['profil'] == "Administrateur" && $_SESSION['code_etablissement'] == '02000')) {
if (isset($rowUser['prev_rea_n']) && $rowUser['prev_rea_n'] == 0) {
echo '<input type="number" id="prev1" name="prev1" class="form-control" placeholder="' . date("Y") . '" aria-describedby="basic-addon2" title="Veuillez selectionner une valeur valide. " onivalid="setCustomValidity(\'Utiliser les points au lieu des virgules.\')" oninput="this.setCustomValidity(\'\')" readonly>';
} else {
echo '<input type="number" id="prev1" name="prev1" class="form-control" placeholder="' . date("Y") . '" aria-describedby="basic-addon2" title="Veuillez selectionner une valeur valide. " onvalid="setCustomValidity(\'Utiliser les points au lieu des virgules.\')" oninput="this.setCustomValidity(\'\')" value="' . (isset($rowUser['prev_rea_n']) ? $rowUser['prev_rea_n'] : null) . '" readonly>';
}
} else {
if (isset($rowUser['prev_rea_n']) && $rowUser['prev_rea_n'] == 0) {
echo '<input type="number" id="prev1" name="prev1" class="form-control" placeholder="' . date("Y") . '" aria-describedby="basic-addon2" title="Veuillez selectionner une valeur valide. " onvalid="setCustomValidity(\'Utiliser les points au lieu des virgules.\')" oninput="this.setCustomValidity(\'\')">';
} else {
echo '<input type="number" id="prev1" name="prev1" class="form-control" placeholder="' . date("Y") . '" aria-describedby="basic-addon2" title="Veuillez selectionner une valeur valide. " onvalid="setCustomValidity(\'Utiliser les points au lieu des virgules.\')" oninput="this.setCustomValidity(\'\')" value="' . (isset($rowUser['prev_rea_n']) ? $rowUser['prev_rea_n'] : null) . '">';
}
}
echobut just the parts that differ. Also: which numbers are you talking about exactly? Is this the validation happening in Javascript directly in the browser? I don't see validation in PHP here.setCustomValidityfunction is the place to implement this, maybe? It's not very clear. (Although you should really also have some server-side PHP validation on top of that, in case anyone decides to bypass the JS, but that would also be in a different place in the code than what you've shown, I would expect). Also "the error message"...which error message is that? Remember we can't see your screen - please be clear and specific about what you are describing.ifstatements only need to vary/add thevalue=... part of the HTML at the end, as far as I can see. Repeating the whole string just causes you extra maintenance and testing whenever you want to amend something.