0

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) . '">';
    }
}
4
  • 1
    very unusual PHP style for me. I would place the complete Input not inside an echo but 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. Commented Jul 22, 2024 at 11:13
  • There doesn't seem to be any validation code directly in what you've shared. I would assume the JavaScript setCustomValidity function 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. Commented Jul 22, 2024 at 11:15
  • Please always ensure you post a minimal reproducible example of the issue, as per How to Ask. You just need to make sure what you're showing us would actually allow us to see the problem, if we ran it ourselves. This code, by itself, doesn't seem to do that. You can edit your post to update it. Thanks. Commented Jul 22, 2024 at 11:15
  • P.S. There seems to be a lot of redundant/repeated code here. Your PHP if statements only need to vary/add the value=... 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. Commented Jul 22, 2024 at 11:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.