Uninitialized string offset: 0
This error is showing because there is an empty value. Try checking if the value is !empty()
(not empty) first. Here’s the source code you provide in your question with my update.
function cf_form_message() {
global $errors;
if ( is_wp_error( $errors ) && empty( $errors -> errors ) ) {
?>
<section class="alertbox-success">
<div class="cf-success">
<p>Thank you for contacting us <?php if ( isset( $_POST['cf-name'] ) && !empty( $_POST['cf-name'] ) ) { echo $_POST['cf-name']; } else { echo 'NO_NAME'; } ?>, a member of our team will be in touch with you shortly.</p>
</div>
</section>
<?php
//Empty $_POST because we already sent email
$_POST = '';
}
else {
if ( is_wp_error( $errors ) && !empty( $errors -> errors ) ) {
$error_messages = $errors -> get_error_messages();
foreach ( $error_messages as $k => $message ) {
?>
<section class="alertbox-error">
<div class="cf-error <?php echo $k; ?>">
<p><?php echo $message ?></p>
</div>
</section>
<?php
}
}
}
}