I've recently tried to add a user registration form to the front end of my site and have used the following form code (based upon this I discovered in an answer by maugly in question Front-end Register Form) in a template file:
<div id="tab2_login" class="tab_content_login" >
<h3>Add a child</h3>
<form method="post" action="<?php echo site_url('wp-login.php?action=register', 'login_post') ?>" class="wp-user-form">
<div class="username">
<label for="user_login"><?php _e('Child Name'); ?>: </label>
<input type="text" name="user_login" value="<?php echo esc_attr(stripslashes($user_login)); ?>" size="20" id="user_login" />
</div>
<div class="email">
<input type="text" name="user_email" value="<?php echo esc_attr(stripslashes($user_email)); ?>" size="25" id="user_email" />
</div>
<div class="login_fields">
<?php do_action('register_form'); ?>
<input type="submit" name="user-submit" value="add child" class="user-submit" />
<?php
$register = $_GET['register'];
if($register == true) {
//now add it to the link database
echo '<p>User Added!</p>';
} ?>
<input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>?register=true" />
<input type="hidden" name="user-cookie" value="1" />
</div>
</form>
</div>
The redirect_to
attribute is set here to the requesting page which is all great when it works by triggering the if block to display an additional success message.
The question I have is when an error is detected in wp-login.php
(such as the username is already in use) how do I get the redirect to come back to this page as opposed to the wp-login generated login box/error display? I can't see any obvious hook to grab hold of (although I've never used actions yet, so could be missing something!)
Help and guidance very much appreciated!
Ryan