Guide: Adding a NEW Custom Profile Field! (MySQL)

Share your CuteNews.RU skins and code snippets.

Guide: Adding a NEW Custom Profile Field! (MySQL)

Postby DarkSlim » Thu Dec 10, 2009 2:19 pm

Hi, it has been asked many times, and I have promised to
write a short guide of how to add a new custom user field. :)

The guide shows how to do in ONLY in MySQL databases, which I also
recommend using over the txtSQL, it is much more secure and durable.

1.
We are going to add a field called "example" to the users (for example of course :wink: )
Enter your MySQL administration (mostly phpMyAdmin), enter your database, enter the 'cute_users' table,
go to the "Structure" after the table fields you will see something like "add new field", you can choose
how many new fields you want to add, and where, click the submit button.

2. Now we are actually adding the field/s (I prefer to add each field at a time).
Fill the table with the field's name, kind of field - choose VARCHAR for maximum compatibility
with input, you can also choose INT for just numbers, DATE for a date etc'
Choose the length, how many characters can/should the field hold, and that's about it
click the submit button and - tada! you've got a new custom user field!

3.
Now's the part where you implement it in the CuteNewsRU system for use.
Open inc/mod/personal.mdu (This is the personal settings page)
You will see all the rows of fields that you have in the personal settings page,
now you need to pick where to put your new field, for EXAMPLE we will put it
after the Homepage field. Find:
Code: Select all
<tr <?=cute_that(); ?>>
<td height="21">&nbsp;&nbsp;<?=$echo['homepage']; ?>
<td height="21" width="400" colspan="2"><input type="text" name="editsite" value="<?=$member['homepage']; ?>" maxlength="50">


This is how a row with a field looks like, we will creat one just after this code,
for our 'example' field, we will add after it:
Code: Select all
<tr <?=cute_that(); ?>>
<td height="21">&nbsp;&nbsp;<?=$echo['Example']; ?>
<td height="21" width="400" colspan="2"><input type="text" name="editexample" value="<?=$member['example']; ?>"  maxlength="20">


Now, what all this says?

  • <?=$echo['Example']; ?> This one calls the name of the field as you have called it in the language files (we will add this later - or you can replace all that just with the name you want)
  • name="editexample" This is the name of the input field that we creat in order to show and edit the field, just pick a suitable name, we will use it later
  • <?=$member['example']; ?> This should be EXACTLY the name of the field as you call in IN THE MYSQL DATABASE, this one shows what the field is currently holding
  • maxlength="20" Change it to whatever number you want, it's the maximum number of characters to be filled in the field
After we have added our field, we need to make sure that the filled in data
will be sent to the database.

Find:
Code: Select all
'homepage'     => replace_comment('add', $editsite),


This is where we send all the filled data to the database to be saved,
After Add:
Code: Select all
'example'     => replace_comment('add', $editexample),


Just replace 'example' with your field's name in the database
and replace $editexample with the name you chose for the input field.

4.
YAY! Now we have the field in the personal setting page, it gets the
field value and saves it perfectly!
Now, you might want to be able to see and edit your users new field
in the edit users page, Open: inc/mod/editusers.mdu

It's kinda the same as before, for example, if we still want to add it
after the Homepage field in the edit user page, Find:
Code: Select all
<tr <?=cute_that(); ?>>
<td height="21">&nbsp;&nbsp;<?=$echo['homepage']; ?>
<td height="21" width="400" colspan="2"><input type="text" name="editsite" value="<?=$row['homepage']; ?>">


Now we just add our field in the same way, for example-
After Add:
Code: Select all
<tr <?=cute_that(); ?>>
<td height="21">&nbsp;&nbsp;<?=$echo['Exapmle']; ?>
<td height="21" width="400" colspan="2"><input type="text" name="editexample" value="<?=$row['example']; ?>">


Same thing, you already got it. ;)
Then, we add it the same way to be sent to the database, for example-
Find:
Code: Select all
'homepage'     => replace_comment('add', $editsite),


After it add your own field as was shown.

5.
Now if you have used the language files, we just need to add the
translations, Open your inc/lang/your_lang folders, and add your field
to the personal.ini and editusers.ini files, for exaple, at the end Add:
Example = "Example Field"


Example is the same name you have used to call the language

That's it! You've got yourself a new custom field!
You can add as many fields as you want, manage them, add them
to profiles, it's awesome!!

Hope it helps, if I will have any updates or additions to this guide
I will update this post.

If you have enjoyed my guide and see it
usefull you can donate to me, the link is in my signiture, it will help
me find the time and encouragement to develope more hacks, plugins
and write more guides as I have a growing list of stuff to make! :wink:

Thank you,

DarkSlim
User avatar
DarkSlim
 
Posts: 296
Joined: Thu Aug 06, 2009 4:18 pm
Location: IL

Postby DarkSlim » Sun Dec 13, 2009 10:58 am

I forgot the "<tr <?=cute_that(); ?>>" in the personal.mdu example
fixed that and made the guide look a bit nicer hehe :)

Also, I want to thank typeman, he made a small donation
which is much appreciated! Thank you. :)

More will be coming soon!
User avatar
DarkSlim
 
Posts: 296
Joined: Thu Aug 06, 2009 4:18 pm
Location: IL

Postby typeman » Sun Dec 13, 2009 11:08 am

DarkSlim wrote:I forgot the "<tr <?=cute_that(); ?>>" in the personal.mdu example
fixed that and made the guide look a bit nicer hehe :)

Also, I want to thank typeman, he made a small donation
which is much appreciated! Thank you. :)

More will be coming soon!


I noticed that when reading through last night. :) But still, great job XD

And no problem :) You deserve it! 8)

I'll give this a go soon and let you know what happens :)
typeman
 
Posts: 102
Joined: Sat Oct 17, 2009 7:38 am


Return to Skins and snippets



Who is online

Users browsing this forum: No registered users and 0 guests