For the most part of this week, I was working on the i-Sana website. If you’re interested, it’s a Dutch website that offers a free digital magazine (or e-magazine) on Health. Anyway, this was an important project for me and I wanted to do everything just right. So, when the bosses requested that we collected the ZIP codes of users, I tried to find a solution.
Since we’re going to be using AcyMailing to send our newsletters, we wanted to use the “core” Joomla registration form, which meant that we had to add a zip code field to it. We pulled it off, of course. I’m not being snobbish, but you know by now that I only discuss “problems” when I managed to solve them, right?
Anyway, below you can find the solution to add custom fields to the registration form yourself.
KNOWN PROBLEMS: There are two known problems when using the method below. Those problems are due to the limitations of HTML forms.
1. You can’t set a minimum required length
2. Users can enter spaces in your new field, instead of ‘real information’.
The steps
1. Edit your Joomla database: The first step is to edit your Joomla database; because you’ll need to store the input for your new field somewhere. So, open your database using phpmyadmin (or another solution; I prefer phpmyadmin myself as it’s a tool that many ISP). Then, make a back-up of the table (something)_users
Add a field to the table (something)_users. The field has to be a text field. Choose a field name that’s related to the extra field you want to create in your form; as you’ll be using this name in the next steps.
2. Editing the registration form: To add the new field to the registration form, you’ll need to edit the following file:
/components/com_user/views/register/tmpl/default.php
In the part of the code where the form is defined, add the following code:
<tr><td height=”40″>
<label id=”zip” for=”postcode”>
<?php echo JText::_( ‘postcode’);?>:
</label>
</td>
<td>
<input class=”inputbox required” type=”text” id=”postcode” name=”postcode” size=”40″>
</td>
In this example, a new text field is added for “Postcode”. You’ll want to changet the references to post code to the field name you used in the previous step.
3. Changing the registration logic: To ensure that the input is written to the Joomla database, you need to edit the following file:
libraries/joomla/database/table/user.php
Under “class JTabeUser extends Jtable” you’ll see the declaration of variables. Add the following code:
“var $postcode = null;”
SUPER IMPORTANT WARNING: the code above must be typed EXACTLY as shown. I accidentaly forgot the space after the =, and I broke the ENTIRE registration process; wondering where I made a mistake.
Of course, you’ll want to change “postcode” to the value you gave your field in step one.
4. Editing the user profile in the back-end: The extra data are now being stored in the database, but you’ll also want them to show up in the Joomla back-end. To achieve this, edit the following file:
/administrator/components/com_users/views/user/tmpl/form.php
Under <form action=”index.php” method=”post” name=”adminForm” autocomplete=”off”>, add the following code :
<tr> <td class=”key”>
<label for=”postcode”> <?php echo JText::_( ‘Postcode’); ?></label>
</td>
<td> <input class=”textbox” type=”text” name=”postcode” id=”postcode” size=”40″ value=”<?php echo $this->user->get(‘postcode’);?>”/>
</td>
</tr>
As usual, replace ‘postcode’ with your own variable!
5. Editing the user profile in the front-end: (added: 17/02/2010) If you want to see the extra data in the user profiles in the front end of the site, you’ll need to make changes to the following file:
/components/com_user/views/user/tmpl/form.php
Under <table cellpadding=”5″ cellspacing=”0″ border=”0″ width=”100%”>; you’ll see that the form is being defined again. Add the following code:
<tr>
<td>
<label for=”postcode”>
<?php echo JText::_(‘Postcode’);?></label>
</td>
<td> <input class=”inputbox required” type=”text” id=”postcode” name=”postcode” size=”40″ value=”<?php echo $this->escape($this->user->get(‘postcode’));?>” >
</td>
</tr>
Once again, you’ll want to change “postcode”.
And bam! You’ve added your field to the registration procedure of Joomla.
(last edited on 17/02/2010. Added “Editiing the user profile in the front-end after comment on the Joomla Forum)
Superman
February 21, 2010 at 8:45 pm
Very helpful guide. Thanks a lot!
Gaurav Kumar
April 8, 2011 at 7:30 am
New field is inserted in form but value is not stored in database
i want to insert values in database
Bonny
May 18, 2011 at 12:10 pm
Hey, did you find out how to store custom values in the database? Thank you in advance
Gaurav Kumar
April 8, 2011 at 8:17 am
i want to add field in form through administrator or back end
mangesh
April 13, 2010 at 12:46 pm
thanks , great work
Ankur
April 26, 2010 at 2:43 pm
Thanks, Really Helpful
waseem
May 2, 2010 at 9:22 am
That good work done thanks thanks alot
oaksolutions
May 11, 2010 at 10:38 am
Thnks a lot
Roberto
May 17, 2010 at 3:15 pm
Hello, I need to add a dropdown list field to my default registration form.
How could I do this?? I am new in all this
Thanks a lot!
Toretto
May 18, 2010 at 8:06 pm
The easy way out would be to answer “by replacing your textbox with a dropdown list”. But I’m guessing that that’s not much of a help for you, is it
I was trying to find an answer to your question yesterday, but I got side-tracked. I’ll try and find a solution later this week
Ray
August 27, 2010 at 4:33 am
Roberto,
First of all thanks for the posting it is very helpful. I added three new fields to my joomla registration: City, State (drop-down), and zip-code. Have not test it, will do that tomorrow.
Adding a state drop-down. You need to follow the same steps as stated here for the text but use this code instead:
user->get(‘state’)) : ?>
<option value="escape($this->user->get( ‘state’ ));?>”>escape($this->user->get( ‘state’ ));?>
Select a State
AK
AL
…
WV
WY
*
You can probably make the drop-down dynamic, If you combine this tutorial with the steps given in http://blog.ninedays.org/2008/01/03/php-state-drop-down-menu-reusable-code/
Best, send me an email if you need the files I coded
vincent
June 24, 2011 at 10:27 am
Hello, nice work i want a drop down menu too in my joomla create a account, i have already add text fields, but can you please make a utube movie so that i can see how to do?
Do i have to change the exact files for text boxes.
greetings
vincen
Ray
August 27, 2010 at 4:37 am
<select name="state" class="inputbox required" id="state"> <?php if($this->user->get('state')) : ?> <option value="<?php echo $this->escape($this->user->get( 'state' ));?>"><?php echo $this->escape($this->user->get( 'state' ));?></option> <?php else : ?> <option value="">Select a State</option> <?php endif ?> <option value="AK">AK</option> <option value="AL">AL</option> ... <option value="WV">WV</option> <option value="WY">WY</option> </select> *Steven Zeegers
August 27, 2010 at 9:37 am
Ray,
I’m glad to see that there are better coders out there than myself!
Would you mind if I ‘devoted’ an article to your update? Of course I’ll be referring to you / your site as the source of the ‘new’ solution.
Let me know what you think!
boomer
February 17, 2011 at 1:28 pm
Cheers Ray, works a charm.
vincent
June 24, 2011 at 1:35 pm
Thanks i did it, i have a lovely pull down menu, thanks 4 sharing.
greetings
vincen
Steven Zeegers
June 28, 2011 at 6:48 pm
Vincent,
Sorry for not replying earlier. I’m glad to see you managed to sort it out, though. Best of luck with your new website!
wolkmx
July 2, 2010 at 10:29 pm
Hi there i found always the same method, that is add a new row to the table of user but i want only to add a select to the form whit countrys, so this part is made, but the problem is that i want that the user name will be like matt@USA, kimberly@MEX, so the list of countrys is not a new row is only a new field to add info to the username field but i don’t know how to make this i do it in jom social whit no problems but in joomla i can´t, do you have some idea?
In jomsocial I used a code like this username.’@’.country (of course whit other syntaxis)
Steven Zeegers
July 4, 2010 at 1:20 pm
W,
I’m not sure if you can do that w/ the standard Registration form. The possibities of the Joomla registration form are a bit “limited” (and it doesn’t look like that’s changing soon). I’m afraid that it’s either going to be
impossible or would require A LOT of coding.
I hope this answer doesn’t discourage you, though. I suggest asking your question at the Joomla forums, maybe the developers for the Joomla core files have the answer?
I hope you find your answer soon!
Ray
August 27, 2010 at 4:43 am
wolkmx, go in the user.php listed in this tutorial go in the function check and after the variables are check do a field merger. You will need to follow all the steps in this tutorial except the field creation in the database.
-Ray
ashfaq ahmed
July 7, 2010 at 12:46 pm
Hi can anyone tell me How to Add radio to the Joomla registration form and also it can save value
Ray
August 27, 2010 at 4:45 am
Thank you for the post! This is very helpful information. Best,
_Ray
Virginia
February 11, 2011 at 12:07 am
I found this for very helpful guide but I need to add radio group. When the user choose the 1st option will see just 1 additional field but if he choose the second option will see 5 additional fields. I know that I have to use ajax to do that. Any hints and ideas?
Chris
February 15, 2011 at 5:00 pm
This was an absolute life saver! I had to adapt to the php in the website itself but this showed me the where and how. The oe thing I would add is that I was using a template from Rockethemes and the template wrote it’s own default.php, which I had to go find instead, so if you’re making changes to default.php and nothing’s happening check your template folders instead.
Many, many thanks for this!
Phearak
March 10, 2011 at 8:00 am
Extra field not work with other template:
I had follow the step above it was work for the default template, but after i change to the other template, the extra field that i was added not show, How to do ? please help…..
Steven Zeegers
March 11, 2011 at 11:33 am
What do you mean? As far as I know, this “fix”isn’t related to your template.
Raymond Moncada
March 11, 2011 at 7:42 pm
The changes are per template basis. If you used a new template you need to update the template to match the steps given above.
Steven Zeegers
March 11, 2011 at 8:00 pm
Maybe I’m missing something, but… I fail to see where template files are being edited?
Raymond Moncada
March 11, 2011 at 9:28 pm
Steven, no you are not missing anything! My mistake, I was thinking of the Joomla 1.5 to Joomla 1.6 upgrade. -Ray
Steven Zeegers
March 11, 2011 at 9:53 pm
Ray, I love mistakes. It’s how this blog was born!
As for the upgrade… Personally, I haven’t tried it yet. Luckily there’s tools like JUpgrade to make things easier.
Robert
April 15, 2011 at 6:44 pm
I was hoping to use this article, but find that the files are totally different for joomla 1.6.
Any help with this issue for the new joomla?
TY
Robert
Steven Zeegers
April 16, 2011 at 7:41 am
I haven’t looked into it yet, Robert. I’m sure this must be possible but I’ll need to do some research first.
Robert
April 16, 2011 at 3:46 pm
Hi Steve,
I have it open and have started on it (multi-tasking), but not sure how it will turn out just yet
Will post back…
R
Steven Zeegers
April 16, 2011 at 7:13 pm
I’d appreciate that, Robert. I should really find some time to start on 1.6 tutorials, but I still have a lot to learn in 1.5… decisions, decisions!
Chris
April 19, 2011 at 9:00 am
Hi,
I was wondering if anyone could help me out.
I want to have a checkbox in my registration form but I can’t seem to accomplish it.
Right now I’m using a textfield and that is working like a charm.
So the only thing I gotta do is change the textfield to a checkbox.
Anyone?
Babatunde Sowobi
April 24, 2011 at 7:42 am
I am following this and I think it is great work.
Solution for 1.6 will be important. Thanks
Tunde
vincent
July 10, 2011 at 8:31 pm
great work but i want to email certail data to the user how do i add the added field to the email wich is send to the new user
greetz vincent netherlands
Omid
July 26, 2011 at 8:27 am
thank you,
I did all the steps, but I have two problem:
1- when I fill the form in the front-end, nothing happens and the empty form loads again.
2- when I fill the form in the back-end, I recieve the error “jtableuser::store failed”
how should I solve the problem? any ideas?
Joomla boy
July 31, 2011 at 6:49 pm
thanks fir this great guide!
but I have a question…
this method is very useful for adding textbox field, but what about other field types?
U want to add (Age) field to the registration form in birthdate form, and showing it in the front-end as an (Age)
how can I do it?
Aef
September 19, 2011 at 11:00 pm
Thaaanks duuude ! this guid helped me much more than joomla.org forum and free form creator components .
You make me happy ,hope somebody makes you happy !
Makenoiz
September 25, 2011 at 10:30 pm
Steven,
Thanks for this. I use JomSocial 2.2.4 and Jom 1.7. The very first thing the client would like his visitors to see at registration is Gender, Birthdate and County, then followed by the good ol’ standards Name, password etc…
I can think of several ways to theroetically do this: one being Collect the data and write it directly to new fields in jos_users then populate jos_community_fieldsValues . What do you think about this process? Do you think there is a better way? Thanks for your expertise.
Wayne Grant
September 29, 2011 at 6:52 pm
I know this is little late, however I have only just come across this tutorial.
i have added to form fields to the user registration form successfully. i would now like to add the extra fields to the email sent to admin.
The fields I have added to the form are, Phone, Mobile, Address, Postcode.
I would like this information to appear in the admin email.
Please help. I have posted this on the joomla forum but no one can help.
Andarc
October 5, 2011 at 9:11 pm
Hi coders,
I am a newbie but managed to fit a custom registration form in the standard user registration process, and I have found this guide very interesting. My question may look silly, but I am going crazy to find a way to set some fields as not required, but I am not coming out of it. I have already changed the db to accept null values for those fields, but when I try to register, it simply does nothing, unless every field is compiled.
Any (precious, vital, you win) advice?
Thank you all
anianitasharmadheeraj
November 4, 2011 at 3:36 pm
thank’s for this help
Awais Ahmad (@Awais_Ahmadd)
November 10, 2011 at 8:35 am
Great Tutorial !
Can you plz explain how to do it in joomla 1.7. Because files in joomla 1.7 are completley changed. Can you plz explain it with respect to joomla 1.7.
Anzar
December 18, 2011 at 1:02 pm
Hi,
great tutorial , guyz plz help me my backend successfully updated with nrew fields but front is nt changing a bit, i tried again nd again , all codes are corrrect but still no new field is added in front end