In my sanitizing script, prior to using the POST Request method to submit this data, I have the following for my textarea input field named 'contact_msg':
if($_POST['contact_msg'] != ''){
$contact_message = sanitize_textarea_field($_POST['contact_msg']);
if(strlen($contact_message < 15)){
$errors .= 'Please enter more information in your message.';
$hasError = true;
} elseif {strlen($contact_message > 2000)) {
$errors .= 'Please shorten your message.';
$hasError = true;
}
}
I'm a little tripped up because I don't think the key/value pair for $_POST['contact_msg']
would be sanitized–only the variable, $contact_message
which by default isn't what is getting passed on submit, thus requiring me to do something else before passing the key/value pair for this input on submit? In other words, how do you actually sanitize $_POST['contact_msg']
? Do you just add something like:
if($_POST['contact_msg'] != ''){
$contact_message = sanitize_textarea_field($_POST['contact_msg']);
if(strlen($contact_message < 15)){
$errors .= 'Please enter more information in your message.';
$hasError = true;
} elseif (strlen($contact_message > 2000)) {
$errors .= 'Please shorten your message.';
$hasError = true;
} else {
$_POST['contact_msg'] = sanitize_textarea_field($_POST['contact_msg'];
}
}
in order to actually sanitize the data being posted?