• If the input type=”number” the sanitize should be sanitize_number_field (it exists?) or I can keep sanitize_text_field ?

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • @sacconi,

    I don’t see anything related specifically to numbers in the WordPress guide on sanitization, so I think using sanitize_text_field should be used.

    If needed, you might also do some validating that the value submitted is acceptable. This would likely be unique based on what your application requires. The documentation linked above contains some examples of how that can be done.

    The link to the page you submitted isn’t a valid page that I can use (https://user-edit.php/?), so if you’d like to share that, I’d be happy to take a look and see if there’s anything else to add.

    Moderator bcworkz

    (@bcworkz)

    For numeric values you can sanitize by type casting to either (int) or (float). For example:
    $safe = (int) $_POST['number'];

    In some cases it’d be even better to also verify the value is within an expected range. For example, if the expected value should always be between 0 and 100, reject a value like -23 or 235.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘sanitize a number field’ is closed to new replies.