Create and activate Joomla users

Aug 17, 2014
Create and activate Joomla users
  • How to create Joomla users from a Fabrik Form.
    In this tutorial I will explain for how to make Fabrik register new users and automatically activate them and redirect them to a Joomla article then send an email to the administrator group with the new user's details.

    Prerequisites
    PHP: 5.3.1 +
    Magic Quotes GPC off
    allow_url_fopen = 1
    Mysql 5.1 + (InnoDB support required)
    Joomla 2.23 Fabrik 3.1
    A Joomla template that Supports the bootstrap framework
    Before you start please check that you have these plugins installed and published -
    Elements used in this tutorial - field,password,yes/no,captcha
    Validations used in this tutorial - notempty,userexists,isemail
    Plugins used in this tutorial - juser,email,updatecol
    In this tutorial I have set all the templates to bootstrap for ease of use.

    Creating a new List

    First of all you need to make a new list, in this tutorial I called the list Users.
    Next you need to add in the elements for the list.

    Elements - Users
    userelements1.jpg
    id - internalID
    date_time - date_time
    Name - field
    UserName - field
    Email - field
    Password - password
    BlockUser - yes/no
    Captcha - Recaptcha

    When setting up the Email field look at the Advanced options and set the dropdown for Input Type to Email.
    This will then check that the user input is a correct format for an email.
    I put Captcha on the form by using Recaptcha just to stop any bots signing up and spamming Viagra adverts.

    Validations

    On this form we want to check that the Name-UserName-Email are not blank. To do this we want to setup each of those fields with a validation rule.
    Edit the elements and add in "notempty" validation rule to each element.
    You can also add the message that will be displayed if the field is empty.
    For the name field I entered the message "Please type in your name"

    ifuserexists.jpg
    UserName validation - Fabrik provides us with an extra validation rule for creating users that checks the users table and makes sure that each user has a unique username. So in the UserName element we want to add in the is "notempty" rule and also the "userexists" rule. I also added in the error message "Sorry this username is already taken, please choose another username"
    "
    To make this work properly we need to edit the Users Form also and turn on Ajax validation, so edit the form and look at the Form Processing tab and turn on Ajax validation.
    This will then run the rules as the user is typing to check that they are entering a unique UserName and also a correct email address.
    Email validation - add the isemail plugin to make Fabrik check that the input is really an email address.

    Form

    Here I will explain the options you need to setup on the Users form.
    First of all we need to load some plugins.

    Plugins
    juserplugin.jpg
    Juser plugin
    The first plugin to load will be the juser plugin, first of all you need to map the fields from the User List table to the plugin.
    Insert image here
    Name field - Name
    Username field - UserName
    Email field - Email
    Password field - Password
    BlockUser field - BlockUser
    UserID field - optional but you could have a seperate hidden element in the form to store a userID
    User Group field - again optional but you could have an element with a checkbox choosing different group memberships and you can use this field to map that to the plugin

    Bypass Joomla settings tab
    Bypass activation - Yes
    Bypass activation - Yes
    Account details email - No
    With these settings the user is created and activated automatically and no email is sent to the user.

    Options tab
    Default user group - Registered

    Synch tab
    Delete users - Yes
    Auto Login - Yes
    Sync on edit - Yes
    With these settings any user deleted by the admin form will also delete the user from the Joomla user table. By setting the autologin to yes when the user submits the form they will be logged in directly. * Tip * by using the standard Joomla Login module and editing the redirect on login URL I was able to redirect the user to any page. So I setup a standard Joomla article called "Thank you for registering" with some text instructions and handy links.

    Email plugin
    emailplugin.jpg
    When a user submits a form and becomes a registered user on the site I want to send an email to the Administrator user group inside Joomla.
    To tab
    Send to group(s) - Administrator
    Options tab
    From - admin@yoursite.com
    Subject - A new user has registered on the site
    Article Text - Pointing to a Joomla article called "New User"
    So create a Joomla article with the content below. Please notice that I am using Fabrik placeholders inside the Joomla article text, change "elementtablename___" to the full element table name such as "x38j_fabrikform_Users".

    Someone just registered on the website. Their details are as follows:-

    Name: {elementtablename___Name} User name: {elementtablename___Username}

    Thier email is {elementtablename___Email}

    Kind Regards,
    Website Admin Team.

    This finishes off all the options you need to set on the Fabrik Users Form.

    List
    Data tab
    Make sure the primary key is the Fabrik internalID and is set to auto increment.

    Access tab
    We want to set everything to Public apart from -
    Delete records - Special
    Empty records - Special
    This way only Administrator accounts can delete or empty user records.


    Plugins
    updatecol1.jpg
    Update Col
    I want the Administrator users to be able to block registered from the users list that they will have access to in the front end. If you use the update col plugin it is very easy to setup a toggle button on the list so the admin users can edit the state directly from the list.
    We need to add this plugin twice and setup an update state for Block user = Yes and Block user = No.

    Block User

    Options tab
    Access - Special
    Button label - Block user
    Button image - arrow-down.png

    Update tab
    Update - select the element BlockUser and set the To input to "1"
    Update message - User Blocked

    Un Block User

    Options tab
    Access - Special
    Button label - Un Block user
    Button image - arrow-up.png

    Update tab
    Update - select the element BlockUser and set the To input to "0"
    Update message - user Unblocked

    Finishing off

    To finish off things you will need to create a Joomla menu link pointing to the Fabrik Form "Users" and leave the permissions to default so that Public can see it.
    For the Administrators you can make a child menu link to the user form link and set the permissions to Special and point the link to the List Users so that they can see the list of users with the Block User buttons that we setup up earlier.
    Publish the default Joomla Login Module and setup the redirect URL to a Thank you for registering Joomla article.
  • Loading...