Ninja Forms User Registration

Create a user in WordPress with a Ninja Form

After searching around for a code snippet that would do the trick when it comes to registering a user through Ninja Forms to no avail, I managed to put one together that works a treat.

All you need to do is change some of the IDs in the code to match your form details and then pop this into your theme’s functions.php file and you’ll be good to go.

You can even create multiple versions of this code snippet, just change up the name nf_create_user where it appears in the code.

UPDATE: 26th October 2016 – With Ninja Forms 3 there was a change to the form processing, check out the 2.x file below for registering users with old versions of Ninja Forms and the 3.x file below for registering with Ninja Forms 3 onwards.

If you’ve got any questions or comments on how this piece of code works, feel free to get in touch with me in the comments below!

26 thoughts on “Ninja Forms User Registration

  1. Hi Steve, thanks for sharing!
    Would this be compatible with buddypress?

    Also, how exactly the user filling Ninja Forms’ form gets his username and password, should these fields be present in the form?

    Thanks, will wait your feedback!

    1. Hi Tom, your’re welcome!

      Yes it should work just fine with BuddyPress, just make sure to include any Buddypress fields using the update_user_meta function after you’ve created the user using wp_insert_user.

      The script I have there is set up to let the user create their own username and password. The password is a required field when creating a user, so while you could create a randomly generated one for them and then send it over to them separately, this way is a little more secure.

  2. Hi Steven,

    That looks great! Does that work for Ninja Forms 3.0? There is no way to register users now it seems. If it does work, is there a way to create bullet points for the password field input?

    Sorry please delete my previous comment. Need to use a different email address.

    Cheers,

    Liv

    1. Hey Liv,

      Thanks! The code didn’t originally work for Ninja Forms 3 but I’ve updated this post to include a new snippet that you should be able to use to do the same thing in the new version of NF.

      The password field seems to have been taken out of Ninja Forms 3, but I’m looking into some code to create a new field to add it back! I’ll keep you posted here on that as well 🙂

      1. Oh wow that’s fast, thanks so much Steven!

        BTW, I’ve asked Ninja Forms about the user registration being taken out, they’re saying it’s coming back probably next month as an add on “User Management”, replacing some of the 2.x “Front End Editor” functionality.

        1. No, doesn’t seem to be supported yet.

          One thing that you could do is add a class (say “password-field”) to a field you want to be a password, and then use CSS to make it look the same:

          input.password-field {
          -webkit-text-security: disc;
          }

          Not as secure, but does the same UX-wise for webkit browsers.

    2. Steven, with your updated code do you feel wordpress user registration will work via Ninja Forms 3.0? In the case of using Buddypress, only normal wordpress user fields will be filled, correct (username, mail, password)?

      Thanks! Liv, also success for your project 🙂

      Regards!

  3. Hi Steven, this was a great tip. I tried using it in version 3, but it did not work. I looked at the Ninja Forms code and there is no filter called my_ninja_forms_processing. I tried to look for someone at the time to save the submission but found nothing. Do you remember seeing anything like it?

    1. Hi Luiz, thanks for letting me know!

      I’ve modified the code to use a filter found here. This should hopefully do what the code intends to do.

      I’ve got to be honest and say that I think the Ninja Forms documentation is pretty poor at the moment, especially when it comes to Ninja Forms 3.0 and showing any differences between 3 and 2.x.

      Let me know how it goes!

      1. I see… Can I use the above plugin in conjunction with a Ninjaforms user registration, as in I have the Facebook button above the Ninjaform?

        1. Probably not, as the Social Login plugin needs to get data from Facebook when registering users if it’s to log users in that way.

          In other words, if you use the Ninja Forms registration users can only login the normal way – but if you use the social login, users can only login that way (unless they set a password later, which isn’t the point of using social login in the first place).

  4. Thank you for making this code available, Steven. I am not a developer by any means, but implementing the 2.9.x code (after adding in the form ID and form fields) helped “fix” the registration ability on the company I work for’s website.

  5. Hi Steven,

    Thanks for this code! It’s working great with NF 3.0. I’ve also implemented the css to hide the password and show bullet points. However the css doesn’t work in Firefox. It states the css is invalid. (-webkit-text-security: disc;)

    I’ve also added additional fields to register the new user as a customer (WooCommerce). But somehow the WooCommerce fields do not get filled in. Any idea how to solve this?

    I’ve used these fields:

    ‘billing_company’ => $website,
    ‘billing_address_1’ => $address,
    ‘billing_postcode’ => $zip,
    ‘billing_city’ => $city,
    ‘billing_country’ => $country,

    Cheers,
    Jaap

    1. Hey Jaap,

      Glad the code’s been of some use to you!

      Didn’t realise that the CSS didn’t work on Firefox, but I’ve found a tiny two line JavaScript snippet you can use to change the input type to password:

      var pass = document.getElementById("ninja_forms_field_3");
      pass.type = 'password';

      All you need to do is replace the “3” with the field ID you want as your password. Add that script somewhere in a child theme / plugin JavaScript file and enqueue it and you should be good to go.

      For the WooCommerce fields, it won’t work because the wp_insert_user function only accepts a limited number of fields. However, what you can do is add some code after the wp_insert_user function, because your user is created then. So for example:

      update_user_meta( $user_id, '_billing_company', $website );

      Can’t quite remember off the top of my head if the meta key should start with an underscore like in the example above or not, so if it doesn’t try it without the underscore. I’ll do some testing later and update if I can!

      Hope that helps and works, if there’s any problems just let me know!

      Cheers,

      Steven

      1. Hi, thanks for the update. Have to look into the enqueuing, something beyond my current knowledge.
        I’ve edited the php so it matches:

        // Create the user and remember the user id
        $user_id = wp_insert_user( $userdata ) ;

        // Use the user id to log in straight away
        wp_set_auth_cookie( $user_id, true );

        update_user_meta( $user_id, ‘billing_company’, $company );
        update_user_meta( $user_id, ‘billing_address_1’, $address );
        update_user_meta( $user_id, ‘billing_postcode’, $zip );
        update_user_meta( $user_id, ‘billing_city’, $city );
        update_user_meta( $user_id, ‘billing_country’, $country );
        update_user_meta( $user_id, ‘vat_number’, $vat );

        }
        }

        unfortunately it doesn’t work… Any idea?

        1. Here’s some info on enqueuing scripts for you.

          Have you tried with the underscore before the billing fields, such as:

          update_user_meta( $user_id, '_billing_company', $company );

          Make sure that the apostrophes around the billing company stuff are correct, as I think some of your examples there were curly aprostophes, which won’t work (although this could be because of the comment formatting!).

          Been a while since I worked with WooCommerce, so can’t remember how the fields off by heart!

  6. Since Ninja Forms uses field keys instead of field id’s, I guess I can just substitute the field id’s in the 3.x script with the field keys in the reg form I just created. There sure are a lot of missing features in 3.x that were available in the older release and I think they are only going to make these features available in additional paid plugins now. I want to use Ninja Forms for registration, multi-page forms, with modal popups and conditional logic. Would be nice to have the ability to place those informational popups (help field) anywhere on the form. I’d also like to be able to have 12 – 15 columns available across the form, and I’m not sure if that is available in the styles and layouts plugin.

  7. Hi Steven,

    I managed to get it working and also create the WooCommerce fields. Made a type-o 🙂

    Anyway. Now I have this working for 1 form. How can I make it work for 2 other forms (NL and DE)? I’ve tried copying the code below the first code, changed all the field form id’s to match the NF id’s. Changed the form number and also changed nf_create_new_user to nf_create_new_user_nl. But it’s not working when filling in the form in another language. What am I doing wrong?

    Cheers,
    Jaap

  8. Am I crazy or does this not work anymore? I can’t get it working despite its seemingly simple premise/code..

Leave a Reply to Steven Kellow Cancel reply

Your email address will not be published. Required fields are marked *