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 am trying to make a user registration form in my site's side bar. Users are able to register but instead of getting a success message, WordPress usually redirect them to 404 page.

Below is my form:

<form id="joinmaillist"   method='post'>
    <table>
        <tr>
            <td>Name</td>
            <td><input type="text" placeholder="Your name here.." name="name" title="Please enter your name" required/></td>
        </tr>
        <tr>
            <td>Email</td>
            <td><input type="email" name="email" placeholder="Your email here.." required/></td>
        </tr>
        <tr>
            <td></td>
            <td style="text-align:right"><input class="submitmail" type="submit" value="Join!" name="joinm"/></td>
        </tr>
    </table>
</form>

and below is my PHP code:

<?php
if (isset($_POST['joinm'])){
    $user_name=$_POST['name'];
    $email =$_POST['email'];


$user_id=  username_exists($user_name);

    if (!$user_id){
        $random_pass = wp_generate_password(12, false);
        $user_id=wp_create_user($user_name, $password, $email);
        header('Location:' . $_SERVER['REQUEST_URI']);
    }else{

    }
}
share|improve this question

1 Answer 1

Look at the code in wp-login.php (line 481 and following). There you can see how registration works.

The names of your form – email, name – are probably overwritten by WordPress. Always use prefixed names in forms to avoid collisions, eg.: ma_email and ma_name.

Prepare incoming data. Do not just write anything someone sends you into your data base. It may be dangerous.

Oh, and welcome to WordPress Stack Exchange! :)

share|improve this answer
    
Thanks I thought wordpress had already prepare all our inputs. So I think i should not worry but now I will be careful –  Mark Adesina Mar 8 '12 at 9:34

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.