Add fields to Joomla! registration form
Posted: Wed Jan 04, 2012 6:06 am
There are many steps
step1:-Add DB field variable to user.php
open file as below:
YOUR_SITE/libraries/joomla/database/table/user.php
/**
* The phone
*
* @var string
*/
var $phone = null;
Step 2. Add field in the DB
ALTER TABLE `jos_users` ADD `phone` int NOT NULL AFTER `username`;
Step 3. Edit Default.php template file for user to add extra field details during registration
open file as below:
YOUR_SITE/components/com_user/views/register/tmpl/default.php
<tr>
<td height="40">
<label id="phonemsg" for="phone">
<?php echo JText::_( 'Phone' ); ?>:
</label>
</td>
<td>
<input class="inputbox required validate-phone" type="text" id="phone" name="phone" size="40" value="" /> *
</td>
</tr>
Step 4. Edit form.php template file for user to edit profile with extra field
open below file:
YOUR_SITE/components/com_user/views/user/tmpl/form.php
<tr>
<td>
<label for="phone">
<?php echo JText::_( 'phone' ); ?>:
</label>
</td>
<td>
<input class="inputbox validate-phone" type="text" id="phone" name="phone" size="40" />
</td>
</tr>
Step 5. Edit default.php to add extended registration columns in the table view
open below file:
YOUR_SITE/administrator/components/com_users/views/users/tmpl/default.php
//table heading
<th width="15%" class="title">
<?php echo JHTML::_('grid.sort', 'phone', 'a.phone', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
</th>
//display data
<td>
<?php echo $row->phone; ?></a>
</td>
Step 6. Edit form.php template file for user to edit profile with extra field to handle user creation or edit by admin
open below file:
YOUR_SITE/administrator/components/com_users/views/user/tmpl/form.php
<tr>
<td class="key">
<label for="phone">
<?php echo JText::_( 'phone' ); ?>
</label>
</td>
<td>
<?php if(!$this->user->get('phone')) : ?>
<input class="inputbox disabled" type="text" name="phone" id="phone" size="40" value="" disabled="disabled" />
<?php else : ?>
<input class="inputbox" type="text" name="phone" id="phone" size="40" value=""/>
<?php endif; ?>
</td>
</tr>
Thats it. Enjoy. Best of luck
step1:-Add DB field variable to user.php
open file as below:
YOUR_SITE/libraries/joomla/database/table/user.php
/**
* The phone
*
* @var string
*/
var $phone = null;
Step 2. Add field in the DB
ALTER TABLE `jos_users` ADD `phone` int NOT NULL AFTER `username`;
Step 3. Edit Default.php template file for user to add extra field details during registration
open file as below:
YOUR_SITE/components/com_user/views/register/tmpl/default.php
<tr>
<td height="40">
<label id="phonemsg" for="phone">
<?php echo JText::_( 'Phone' ); ?>:
</label>
</td>
<td>
<input class="inputbox required validate-phone" type="text" id="phone" name="phone" size="40" value="" /> *
</td>
</tr>
Step 4. Edit form.php template file for user to edit profile with extra field
open below file:
YOUR_SITE/components/com_user/views/user/tmpl/form.php
<tr>
<td>
<label for="phone">
<?php echo JText::_( 'phone' ); ?>:
</label>
</td>
<td>
<input class="inputbox validate-phone" type="text" id="phone" name="phone" size="40" />
</td>
</tr>
Step 5. Edit default.php to add extended registration columns in the table view
open below file:
YOUR_SITE/administrator/components/com_users/views/users/tmpl/default.php
//table heading
<th width="15%" class="title">
<?php echo JHTML::_('grid.sort', 'phone', 'a.phone', @$this->lists['order_Dir'], @$this->lists['order'] ); ?>
</th>
//display data
<td>
<?php echo $row->phone; ?></a>
</td>
Step 6. Edit form.php template file for user to edit profile with extra field to handle user creation or edit by admin
open below file:
YOUR_SITE/administrator/components/com_users/views/user/tmpl/form.php
<tr>
<td class="key">
<label for="phone">
<?php echo JText::_( 'phone' ); ?>
</label>
</td>
<td>
<?php if(!$this->user->get('phone')) : ?>
<input class="inputbox disabled" type="text" name="phone" id="phone" size="40" value="" disabled="disabled" />
<?php else : ?>
<input class="inputbox" type="text" name="phone" id="phone" size="40" value=""/>
<?php endif; ?>
</td>
</tr>
Thats it. Enjoy. Best of luck