Add additional fields to a Joomla 1.5 registration form

There is no easy way to add additional fields to a default Joomla 1.5 registration form. This can be done by installing third party extensions or changing some core Joomla files. Changing core files is normally not recommended as Joomla update may overwrite them. If you upgrade to Joomla 1.6/1.7 it can be achieved much easier as explained in this article. However if you don't want to upgrade this article explains how you can add additional field by changing core files.

In this example we will add an optional "Address" field to a default Joomla 1.5 registration form, but obviously you can add more fields if required.

1. Add additional field to the database table

Login into your phpMyAdmin control panel, open jos_users table, click on Structure tab.
Add 1 field After email and click GO
Add additional fields to a Joomla 1.5 registration form
Fill following fields:
Field: cust_address
Type: TEXT
Click SAVE
Add additional fields to a Joomla 1.5 registration form

2. Change registration form

This will add a new address field into user registration form.

Edit file: components/com_user/views/register/tmpl/default.php

In section:
<form action="<?php echo JRoute::_
after
<tr>
<td height="40">
<label id="emailmsg" for="email">
<?php echo JText::_( 'Email' ); ?>:
</label>
</td>
<td>
<input type="text" id="email" name="email" size="40" value="<?php echo $this->escape($this->user->get( 'email' ));?>" maxlength="100" /> *
</td>
</tr>
Add following code:
<tr>
<td height="40">
<label id="cust_address" for="cust_address">
<?php echo JText::_( 'Address'); ?>:
</label>
</td>
<td>
<input type="text" id="cust_address" name="cust_address" size="40" maxlength="200" value="<?php echo $this->user->get('cust_address'); ?>"/>
</td>
</tr>

3. Add a new variable to user.php

This will ensure new Address entry is saved to the database.

Edit file: libraries/joomla/database/table/user.php

Just after:
class JTableUser extends JTable
{
Add
:
var $cust_address = null;

4. Change the back-end

This will allow to view and edit new Address field in the back-end.

Edit file: administrator/components/com_users/views/user/tmpl/form.php

In section:
<form action="index.php" method="post" name="adminForm" autocomplete="off">
after:
<tr>
<td>
<label for="email">
<?php echo JText::_( 'Email' ); ?>
</label>
</td>
<td>
<input type="text" name="email" id="email" size="40" value="<?php echo $this->user->get('email'); ?>" />
</td>
</tr>
Add following code:
<tr>
<td>
<label for="cust_address">
<?php echo JText::_( 'Address'); ?>
</label>
</td>
<td>
<input type="text" name="cust_address" id="cust_address" size="40" value="<?php echo $this->user->get('cust_address'); ?>" />
</td>
</tr>

Tested on Joomla 1.5.23

Comments  

Simon
# Simon 2012-05-04 00:19
Really simple but still decent guide.

Thank you, you solved my problem!

+1
Jim
# Jim 2012-01-13 01:26
Thank you very much for this tutorial! It helped me to add new fields to my form.
Danny
# Danny 2012-01-10 07:06
Can I change the registration form only to add a required field a simple field like this:
Code:<tr>
<td>
<label for="math_check">
<?php echo "3+6=?"; ?>
</label>
</td>
<td>
<input class="required inputbox" type="text" name="math_check" id="math_check" size="5" value="9" />
</td>
</tr>


Anyway, you got the point, how can I do that?
Danny
# Danny 2012-01-10 07:10
Of course this field must be required and users and bots cannot go through.
mihai
# mihai 2011-09-05 13:11
After i make an test user i dont know why the new field dont save the content.

eg: i add HOW DID YOU FIND US field with next options, google, etc etc...i try to register fill up all fields, choose the right option and when i register my option is not saved and is still default. ALso when i go into backend if i try to setup for the nex user this new option i selecte and when i apply is return to the default field.

Any ideea?
Web
# Web 2011-09-05 17:10
works fine for me. Probably because you used drop down rather than standard text field. Did you try with normal "text" type input?

Newsletter

Subscribe to receive occasional updates on new posts.
Your email will not be used for any other purpose and you can unsubscribe at any time.
Please wait