Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 &amp; 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

share|improve this question
1  
Please, don't use @ error suppression. That just hides errors. Do checks like isset(), ! empty() and similar instead. The current way you'll never be able to get any debug info. –  kaiser Aug 16 '13 at 12:28
    
Post your form code and explain the context. Why are you running this on init? That runs on every page load, which seems wasteful. –  s_ha_dum Aug 16 '13 at 13:23
    
Agreed, i run it on init rather than running it from my template file where my form is. (This produces the same results) Where would you put it? –  user195257 Aug 16 '13 at 14:12

1 Answer 1

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_die( '<pre>' . var_export( $wp->public_query_vars, true ) . '</pre>' );

$wp is a WordPress global variable. wp_die() should break your page and give you list similar to this:

array (
  0 => 'm',
  1 => 'p',
  2 => 'posts',
  3 => 'w',
  4 => 'cat',
  5 => 'withcomments',
  6 => 'withoutcomments',
  7 => 's',
  8 => 'search',
  9 => 'exact',
  10 => 'sentence',
  11 => 'calendar',
  12 => 'page',
  13 => 'paged',
  14 => 'more',
  15 => 'tb',
  16 => 'pb',
  17 => 'author',
  18 => 'order',
  19 => 'orderby',
  20 => 'year',
  21 => 'monthnum',
  22 => 'day',
  23 => 'hour',
  24 => 'minute',
  25 => 'second',
  26 => 'name',
  27 => 'category_name',
  28 => 'tag',
  29 => 'feed',
  30 => 'author_name',
  31 => 'static',
  32 => 'pagename',
  33 => 'page_id',
  34 => 'error',
  35 => 'comments_popup',
  36 => 'attachment',
  37 => 'attachment_id',
  38 => 'subpost',
  39 => 'subpost_id',
  40 => 'preview',
  41 => 'robots',
  42 => 'taxonomy',
  43 => 'term',
  44 => 'cpage',
  45 => 'post_type',
  46 => 'post_format',
)

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.

<label for="name">Your Name<span class="required">*</span></label>
<input type="text" name="name" id="name" class="required">

Item 26 indicates that this name will be hijacked by WordPress. Use something else:

<label for="user_name">Your Name<span class="required">*</span></label>
<input type="text" name="user_name" id="user_name" class="required">
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.