Adding more fields to the Joomla Registration page

Warning: Joomla Hack! The following code involves modifying the core Joomla code. This has intrinisc drawbacks, i.e. any time you upgrade you'll have to redo the code, or lose this functionality

Make sure you take backups before you do this change! 

The Joomla Registration page usually contains enough information for most website. Users who want enhanced user information, typically go for Community Builder which allows extensive user registration fields. However, it is entirely possible to create additional registration fields without installing any components, by modifying a few lines in the Joomla core code. Here's how to do it.

In this example, we will be adding Business and Phone to the user registration field, however you can modify the example to add any fields you want to.

Step 1 - Add fields to the Users table

The first thing you need to do is to add the new fields into the Users table into the database. Using phpmyadmin or otherwise add the fields to the users tabl. The following SQL command adds the fields, however you can add these in any way you want:

 

ALTER TABLE jos_users ADD business VARCHAR (100) NO NULL AFTER name;
and
ALTER TABLE jos_users ADD phone VARCHAR (100) NO NULL AFTER business;


Once you have created the columns, verify that they have been created correctly and move on to the next step.

Step 2 - Modify the code

You'll need to modify a total of 4 files:

1. Modify the user class to include the new files in libraries/joomla/database/table/user.php

    var $name = null;
    /**
    * The login name
    *
    * @var string
    */

    var $username = null;

var $business = null;
var $phone = null;

2. Modify the code which displays the registration page components/com_user/views/register/tmpl/default.php 

    <tr>
    <td width="30%" height="40">
    <label id="namemsg" for="name"><?php echo JText::_( 'Name' ); ?>: </label> </td>
    <td>
    <input type="text" name="name" id="name" size="40" value="<?php echo $this->user->get( 'name' );?>" class="inputbox required" maxlength="50" /> * </td>
    </tr>

<tr>
<td width="30%" height="40">
<label id="businessmsg" for="business"><?php echo JText::_( 'Business' ); ?>: </label> </td>
<td>
<input type="text" name="business" id="business" size="40" value="<?php echo $this->user->get( 'business' );?>" class="inputbox required" maxlength="50" /> * </td>
</tr>
<tr>
<td width="30%" height="40">
<label id="phonemsg" for="phone"><?php echo JText::_( 'Phone' ); ?>: </label> </td>
<td>
<input type="text" name="phone" id="phone" size="40" value="<?php echo $this->user->get( 'phone' );?>" class="inputbox required" maxlength="50" /> * </td>
</tr>

     

    3. Modify the view of the users list: components/com_user/views/user/tmpl/form.php



    <tr>

      <td width="120">
      <label for="name">
      <?php echo JText::_( 'Your Name' ); ?>:
      </label>
      </td>
      <td>
      <input class="inputbox" type="text" id="name" name="name" value="<?php echo $this->user->get('name');?>" size="40" />
      </td>
      </tr>
      <tr>

    <td width="120">
    <label for="business">
    <?php echo JText::_( 'Business' ); ?>:
    </label>
    </td>
    <td>
    <input class="inputbox" type="text" id="business" name="business" value="<?php echo $this->user->get('business');?>" size="40" />
    </td>
    </tr>
    <tr>
    <td width="120">
    <label for="phone">
    <?php echo JText::_( 'Phone' ); ?>:
    </label>
    </td>
    <td>
    <input class="inputbox" type="text" id="phone" name="phone" value="<?php echo $this->user->get('phone');?>" size="40" />
    </td>
    </tr>

     

    4. Edit the page which displays the users in the backend: administrator\components\com_users\views\user\tmpl\form.php

    <tr>
                        <td class="key">
                            <label for="email">
                                <?php echo JText::_( 'Email' ); ?>
                            </label>
                        </td>
                        <td>
                            <input class="inputbox" type="text" name="email" id="email" size="40" value="<?php echo $this->user->get('email'); ?>" />
                        </td>
                    </tr>

    <tr>
                        <td class="key">
                            <label for="business">
                                <?php echo JText::_( 'Business' ); ?>
                            </label>
                        </td>
                        <td>
                            <input class="inputbox" type="text" name="business" id="business" size="40" value="<?php echo $this->user->get('business'); ?>" />
                        </td>
                    </tr>
                    <tr>
                        <td class="key">
                            <label for="phone">
                                <?php echo JText::_( 'Phone' ); ?>
                            </label>
                        </td>
                        <td>
                            <input class="inputbox" type="text" name="phone" id="phone" size="40" value="<?php echo $this->user->get('phone'); ?>" />
                        </td>
                    </tr>

     

    That's it! You now have a couple of additional fields in the users table, and more information available to use. Thanks goes to jtullous from the Joomla Forums who supplied the code.

    Make sure you take backups before you do this change!

       

    Featured On

    Inc Magazine Logo  

    Sitepoint logo  

    CSS Tricks logo   

    webdesignerdepot logo   WPMU DEV logo   

    and many more!

    Where are we hosted?

    This site is proudly powered by FAST VPS InMotion Servers and given an insane speed thanks to MaxCDN!

    Web Hosting MaxCDN - Speed up your website

    New! DIVI 3.1 WordPress Template + PageBuilder

    You'll surely create a perfect website with Divi 3.1!

    Get an exclusive 10% OFF for CollectiveRay visitors until

    Divi 3

     

    Monstroid2 (Updated!)

    The best-selling template from TemplateMonster has been given an awesome upgrade!

    We've got an exclusive 10% OFF for CollectiveRay visitors on Monstroid2 until - use Coupon Code: collectiveray

    Monstroid2 Super Update

     

    TemplateMonster Bundles

    Awesome bundles for awesome websites. $1300 worth of products for $49 only!

    We've got an exclusive 10% OFF for CollectiveRay visitors until - use Coupon Code: collectiveray

    TemplateMonster Bundles

     

    The Outstanding HungryJPEG Bundles

    AWESOMENESS! Bundles of premium font + graphic packs at more than 96% OFF!  Get a bundle for just $9 - ONLY!

    The Hungry JPEG Awesome font bundles

     

    Advertise on CollectiveRay.com

    CollectiveRay (formerly known as DART Creations) is interested in developing partnerships with mutual benefit. If you like the stuff we publish and would like to develop a relationship, we'd be happy to hear from you. Go on - drop us a line - we'd love to hear from you :-)

     

     

    Disclosure: CollectiveRay is funded personally out of pure passion for helping people working with websites. We do however generate some income through recommendations of products. This means if you click on a link and purchase an item we link to, we will receive a small sum out of that sale. We usually partner with vendors to make your purchase cheaper than buying direct.

    Popular Content

    Joomla extensions to take your website to the NEXT level

    Is your Joomla website reaching its full potential? We install many of these extensions on almost ALL of our Joomla sites - why don't you check them out our list of Joomla Extensions and see whether you can take your site to the next level?

    who are we?

    CollectiveRay is run by David Attard - working in and around the web design niche for more than 12 years, we provide actionable tips for people who work with and on websites. We also run DronesBuy.net - a website for drone hobbyists.

    David attard

    Follow us on Social

    Follow us on Facebook   Follow us on Google+   Subscribe to our RSS Feed   Follow us on Twitter