Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Adding First and Last name as required fields to the registration form?

retoidretoid New
edited February 2012 in Vanilla 2.0 - 2.8

I remember on V1 there was a plugin to allow me to require a first and last name to be entered on the registration for for all new applicants. All user profiles would display the users full name.

Would there be any plugin i am not finding or is there a somewhat easy way to achieve this?

This is extremely important for people running forums that require a certain legitimacy to prevent trolling and anonymity etc.

Thanks

Best Answers

  • jspautschjspautsch ✭✭✭
    Answer ✓

    Stole x00's trick from this thread to make it work, apparently events haven't been added yet.

    public function EntryController_Render_Before($Sender,$Args)
    {
        if(strcasecmp($Sender->RequestMethod,'register')==0)
        {
            $RegistrationMethod = Gdn::Config('Garden.Registration.Method');
            $Sender->View =$this->GetView( 'register'.strtolower($RegistrationMethod).'.php');
        }
    }
    

    I actually have the plugin working now, soooo, yeah, will get you a download link.

Answers

  • I was just about to ask the same question :)

    This is very important for my community too, any solution is highly apreciated

  • Bumpity bump

  • x00x00 MVP
    edited February 2012

    You simply add the column to the user table and it should show up. Required fields are not null.

    Additional validation will require hooks.

    grep is your friend.

  • I wish that popped into my head as "simple". I am no dev, sorry.

    I understand a bit of html, css and js. Though jumping into vanilla and trying to figure this out has been no easy task for me. Could you explain a bit more on what I would do to make that happen?
    I'm running Version 2.0.18.1

    Thanks

  • jspautschjspautsch ✭✭✭
    edited February 2012

    No plugin currently exists with this functionality it seems, so you or someone else would have to design it. It should be a fairly simple to make, I would thoroughly explore the developer documentation here and on the Vanilla Wiki.

    First you need to create your class.firstlastnameplugin.plugin.php file and define your plugin...

    class FirstLastNamePlugin extends Gdn_Plugin
    {
        public function Setup()
        {
            $this->Structure();
        }
    }
    

    Then within that, after Setup, define another function to add the columns to the database...

    public function Structure()
    {
        Gdn::Structure()
            ->Table('User')
            ->Column('FirstName', 'varchar(50)')
            ->Column('LastName', 'varchar(50)')
            ->Set();
    }
    

    Then you just need to hook into the registration form and add a couple new fields and validation... not sure how to do that, at first glance don't see any events to handle. Would rather not replace the entire view.

  • jspautschjspautsch ✭✭✭
    Answer ✓

    Stole x00's trick from this thread to make it work, apparently events haven't been added yet.

    public function EntryController_Render_Before($Sender,$Args)
    {
        if(strcasecmp($Sender->RequestMethod,'register')==0)
        {
            $RegistrationMethod = Gdn::Config('Garden.Registration.Method');
            $Sender->View =$this->GetView( 'register'.strtolower($RegistrationMethod).'.php');
        }
    }
    

    I actually have the plugin working now, soooo, yeah, will get you a download link.

  • You guys are awesome!

    /me uploads cookie to your energizer

  • jspautschjspautsch ✭✭✭
    edited February 2012

    Hmmm, only problem is you would have to either remove the columns you added or set them to allow NULL when the plugin is disabled, otherwise after adding the plugin your registration would be broken once you disabled it.

    Anyone have any idea how to do that?

    [Edit] Nevermind, this seemed to work...

    public function OnDisable()
    {
        Gdn::Structure()
        ->Table('User')
        ->Column('FirstName', 'varchar(50)', NULL)
        ->Column('LastName', 'varchar(50)', NULL)
        ->Set();
    }
    
  • Thank you again for making this happen.

    Since there are already several current users imported from vanilla 1 to vanilla 2.
    There does not seem to be any easy to way to edit current users to fill in their first and last name.

  • There is a problem where it redirects the registration confirmation view back to the registration form, will work on a fix. It still works, but might confuse users.

  • retoid said:
    Since there are already several current users imported from vanilla 1 to vanilla 2.
    There does not seem to be any easy to way to edit current users to fill in their first and last name.

    I'll work on allowing the users to edit the fields after registering.

  • Thank you again.

    It's currently installed on my forum and I tested registering a new user.
    It's requiring the new fields and displaying them properly. :)

  • jspautschjspautsch ✭✭✭
    edited March 2012

    retoid said:
    Since there are already several current users imported from vanilla 1 to vanilla 2.
    There does not seem to be any easy to way to edit current users to fill in their first and last name.

    Added in version 1.1, users can edit their own names and admins can edit user names from the dashboard.

  • Awesome, you are the man!
    Thank you very much

  • Just ran into a problem.
    A new user is getting an error: "Your humanity is suspect... please try again" and is unable to create an account.
    I am not sure why this is happening so I decided to go to Users and add a new user. Here is where the fields for first name and last name are missing. Since there are no fields here it will not allow me to save the new user as First and Last names are required. Any way to add those fields to the Add User form?

    Thanks

  • Hmmm, I thought I already did add those fields to the Add User form? Do they show up when editing a user?

  • Yes they show up when editing an user but not Adding an User from the dashboard/user page

Sign In or Register to comment.