PHP Form Validation: Alter a value in $_Post

This entry is part 5 of 7 in the series PHP Form Validation

If you want to use the whitespace-trimmed value subsequently in your program, alter the value in $_POST and the test the altered value.

$_POST['name'] = trim($_POST['name']);

if (strlen($_POST['name']) == 0) {
    $errors[] = 'Your name is required.';

Because $_POST is auto-global, a change to one of its elements inside the validate_form() function persists to other uses of $_POST after the change in another function, such as process_form().

Series Navigation<< PHP Form Validation: Removing whitespace
PHP Form Validation: Number ranges >>

Leave a comment

Leave a Reply