I’m posting a form to insert a new user and hooking my function to ‘init’. This code is in my mu-plugins folder.
The user gets inserted fine, but the page is not loaded after wards.
My form action is empty, so the form should post the same page (which i want) However, i just get a blank page (with header and footer) and the title says page cannot be found.
It looks as if there is a problem with the page’s post?
Below is my function code
/*
* Register a new reminder_service user
*/
function reminder_register(){
if(@$_POST['reminder_register']){
$user["user_login"] = $_POST["email"];
$user["user_pass"] = $_POST["password"];
$user["user_email"] = $_POST["email"];
$user["display_name"] = $_POST["name"];
$user["user_nicename"] = strtolower(str_replace(" ", "-", $_POST["name"]));
$user["role"] = 'reminder_service';
$user["user_registered"] = date('Y-m-d H:i:s');
$user["show_admin_bar_front"] = false;
$user_id = wp_insert_user($user);
if(is_int($user_id)){
echo 'yes';
}else{
foreach($user_id->errors as $error){
foreach($error as $e)
echo $e."<br />";
}
}
}
}
add_action('init', 'reminder_register');
This is my form code
<form action="" id="reminder_register_form" method="post">
<fieldset class="blue">
<span><legend><div class="circle c_1"></div> Your Details</legend></span>
<ul class="form floated">
<li>
<label for="name">Your Name<span class="required">*</span></label>
<input type="text" name="name" id="name" class="required">
</li>
<li class="right">
<label for="postcode">Postcode<span class="required">*</span></label>
<input type="text" name="postcode" id="postcode" class="required">
</li>
<li>
<label for="email">Your Email<span class="required">*</span></label>
<input type="email" name="email" id="email" class="required">
</li>
<li class="right">
<label for="mobile">Mobile No<span class="required">*</span></label>
<input type="text" name="mobile" id="mobile" class="required">
</li>
<li>
<label for="password">Password<span class="required">*</span></label>
<input type="password" name="password" id="password" class="required">
</li>
<li class="right">
<label for="password_confirm">Confirm Password<span class="required">*</span></label>
<input type="password" name="password_confirm" id="password_confirm" class="required">
</li>
<li>
<label for="terms" class="radio_label">I agree with the Terms of Service, the Privacy Policy and Terms & Conditions of the Good Dealer Scheme Reminder Service</label>
<input type="checkbox" name="terms" id="terms" class="required" value="yes">
</li>
<li class="right">
<label for="communication" class="radio_label">Please select if you are happy to receive further communication from the Good Dealer Scheme. </label>
<input type="checkbox" name="communication" id="communication" value="yes">
</li>
</ul>
</fieldset>
<div class="submit_button_container">
<input type="submit" value="Register" name="reminder_register" class="orange">
<label><span class="required">*</span> Please complete these fields before clicking the register button</label>
</div>
</form>
The way i want this to work is to submit the form to the same page, and show appropriate content based on the result of the user insert
The 404 page problem in the form field names. There is a list of public query variables that WordPress uses. If one of your form fields uses one on of those names, the result is not guaranteed.
The list is available somewhere in the Codex, but you can print the list in your page template file. Add this line near the top:
$wp
is a WordPress global variable. wp_die() should break your page and give you list similar to this:Do not name any of your fields those names and you should get to your correct page.
For example, one of your fields is named
name
.Item
26
indicates that thisname
will be hijacked by WordPress. Use something else: