OK, so it’s clear that the redirection won’t work in this case. You can’t output any HTML before sending headers, and redirection sends a header.
The easiest (but bad) solution is to move you PHP code to the top of that page template:
<?php
/* Template Name: Register Page */
$err="";
$success="";
global $wpdb, $PasswordHash, $current_user, $user_ID;
if(isset($_POST['task']) && $_POST['task'] == 'register' ) {
...
wp_redirect('xxxxxxxxxxxxxxxxxx');
die();
}
wp_head(); the_post();
?>
...
<div class="half-d" id="account-log">
<form method="post">
...
</form>
</div>
...
You also have to die
the script after doing redirection.
But… This isn’t very good way to do this. You should not process any forms directly in templates – templates are for displaying site and not for processing any data and any logic.
Much nicer way would be to send that form to wp_admin_url('admin-post.php)' and processing it using [
admin_post_(action)`]1.