View Single Post
  #23 (permalink)  
Old 02-10-2008, 02:57 PM
redwine's Avatar
redwine redwine is offline
Pligg Donor
 
Join Date: Jul 2007
Location: Canada
Posts: 216
Thanks: 20
Thanked 102 Times in 65 Posts
Follow these steps

To add fields to the registration, you have to do the following:
1.Define the fields you want to add
2.Create the fields in the users table
3.Modify /templates/yget/register_step_1.tpl or register_center.tpl in 9.9.0
4.Modify /libs/user.php
5.Modify /register.php
6.modify /templates/yget/user_center.tpl
7./templates/yget/profile_center.tpl
8./profile.php
For instance, you want to add a textarea for the user to add a bio and a field where they can specify their interests:

Open your database and run this sql code from the users table:

To Add the bio column (I am assigning a TEXT type to hold a long text):

Note: substitute pligg_ with whatever prefix you have chosen during the installation.
Code:
ALTER TABLE `pligg_users`ADD COLUMN`user_bio` TEXT NULL

To add the interests field:
Code:
ALTER TABLE `pligg_users`ADD COLUMN`user_interests` varchar(128) NULL

Open /libs/lang.conf or /languages/lang_english.conf in 9.9.0 and add this under the “User Profile” section:
Code:
//<SECTION>USER PROFILE</SECTION><ADDED>0.5</ADDED>
PLIGG_Visual_User_Bio = "Biography"
 
//<SECTION>USER PROFILE</SECTION><ADDED>0.5</ADDED>
PLIGG_Visual_User_Interests = "Interests" 
And add this under the “Register” section:
Code:
 
//<SECTION>REGISTER</SECTION><ADDED>0.5</ADDED>
PLIGG_Visual_Register_Bio = "Enter your Biography"
Save and close.
Open /templates/yget/register_step_1.tpl or register_center.tpl in 9.9.0:

Add this after the “Verify Password” code:
Code:
<br/><br/>
Code:
<b>{#PLIGG_Visual_Register_Bio#}:</b>
<br/><textarea name="bio" rows="10" cols="60" id="bio" WRAP=SOFT></textarea><br/><br/>
<b>{#PLIGG_Visual_User_Interests#}:</b><br />
<label class="req">{#PLIGG_Visual_User_Interests#}:</label>
             <br/><input type="text" id="interests" name="interests" value=""  class="textinput" size="20" tabindex="26" maxlength="128" /> 
Save and close.
Open /register.php

If you are NOT using 9.9.0
Go to function do_register1() section and anywhere after $username=$_POST['username']; the following:
Code:
$bio=$_POST['bio'];
$interests=$_POST['interests']; 
Go to //INSERT VALUES INTO DATABASE section and insert the text in blue as they appear in the code:

Code:
$sql1="INSERT INTO " . table_users . " (user_login, user_email, public_email, user_pass, user_date, user_ip, ………., user_bio, user_interests) VALUES ('$username', '$email', '$publicemail', '$saltedpass', now(), '$userip', ……., '$bio', '$interests')" ; 
If you ARE using 9.9.0

go to if(isset($_POST["regfrom"])) { and add the following in the case 'full': and case 'sidebar':

$bio = $db->escape(trim($_POST['bio']));

Few lines below in the if(isset(... section, add this:

if(isset($bio)){$main_smarty->assign('reg_bio', $bio);}

Change this code (changes are in red):

if($error == false){
register_add_user($username, $email, $password, $password2, $bio);
}


change (in red): the function register_add_user($username, $email, $password, $password2, $bio){

After $user = new User(); add:

$user->bio = $bio;

Save and close.

Up to here, we added the new fields and captured the data into the database.
Now we need to modify few files to get the data to the user profile.
Open /libs/user.php
Under the Class User { section, add this:

Code:
var $interests = ''; 
var $bio = ''; 
If you are using 9.9.0:

Locate function Create(){ and add this (in red) to the if ($db->query

, user_bio) VALUES

And in the query, add (in red)

'".$userip."', '".$this->bio."')")) {

Look for function store() { and insert this anywhere after $user_email = $db->escape($this->email);
Code:
$user_interests = $db->escape($this->interests);
$user_bio = $db->escape($this->bio); 
Go down few lines to where it starts with $sql .= " , user_login=
And insert the following right before the WHERE
Code:
, user_bio='$user_bio', user_interests='$user_interests' 
Go to function read() { and insert the following anywhere before the line that reads $this->read = true;

Code:
$this->bio = $user->user_bio;
$this->interests = $user->user_interests; 
Look for function fill_smarty($main_smarty, $stats = 1){
And insert this before the line that reads if($stats == 1){

Code:
$main_smarty->assign('user_interests', $this->interests);
$main_smarty->assign('user_bio', $this->bio); 
Save and close.
Open /templates/yget/user_center.tpl
Look for <div id="personal_info">
And insert the following anywhere you want them to appear in the profile:

Code:
{if $user_bio ne ""}
 <tr>
<td><strong>{#PLIGG_Visual_User_Bio#}:</strong></td>
             <td>{$user_bio}</td>
 </tr>
{/if}
 
{if $user_interests ne ""}
 <tr>
             <td><strong>{#PLIGG_Visual_User_Interests#}:</strong></td>
             <td>{$user_interests}</td>
 </tr>
{/if} 
Save and close.

Open /profile.php
Look for function show_profile() {
And insert the following before the line // pagename

Code:
$main_smarty->assign('user_interests', $user->interests);
$main_smarty->assign('user_bio', $user->bio); 
Look for function save_profile() {
And insert the following before the line // module system hook

Code:
$user->interests=cleanit($_POST['interests']);
$user->bio=cleanit($_POST['bio']); 
Save and close.

Open /templates/yget/profile_center.tpl
And insert this at the end of the first table before </table> Don’t forget to assign the tabindex.

Code:
<tr>
 <td><label class="req">{#PLIGG_Visual_User_Interests#}:</label>
             <input type="text" id="interests" name="interests" value="{$user_interests}"  class="textinput" size="30" tabindex="" maxlength="128" />
 </td>
 <td>&nbsp;</td>         
</tr>
<tr>
 <td><label class="req">{#PLIGG_Visual_User_Bio#}:</label>
<textarea name="bio" rows="10" cols="60" id="bio"  WRAP=SOFT>{$user_bio}</textarea>
 </td>
 <td>&nbsp;</td>         
</tr> 
Save and close
Et voila, you’re done!

Last edited by redwine; 02-14-2008 at 01:14 PM..
Reply With Quote
The Following 4 Users Say Thank You to redwine For This Useful Post: