Welcome to Geeklog Thursday, October 19 2017 @ 08:35 am EDT


Status: offline

kilerb

Forum User
Regular Poster
Registered: 19/03/2008
Posts: 119
Hi... I've got my site up and running nicely... I do want to have the users that register to have their full name required upon doing so.

I went through the tutorial and when I finished my site gave me a blank screen. So, I turned the customization to false in config.php. The fields were there but didn't work properly. Like it said "you didn't type your email address twice when there is only 1 email address field. So I turned it back to the way it was for now.

In my lib-custom file I changed this....

PHP Formatted Code
/* Creat any new records in additional tables you may have added  */
/* Update any fields in the core GL tables for this user as needed */
/* Called when user is first created */
function CUSTOM_userCreate ($uid)
{
    global $_CONF, $_TABLES;

    // Ensure all data is prepared correctly before inserts, quotes may need to
    // be escaped with addslashes()
    $email = '';
    if (isset ($_POST['email'])) {
        $email = COM_applyFilter ($_POST['email']);
        $email = addslashes ($email);
    }

    $homepage = '';
    if (isset ($_POST['homepage'])) {
        $homepage = COM_applyFilter ($_POST['homepage']);
        $homepage = addslashes ($homepage);
    }

    $fullname = '';
    if (isset ($_POST['fullname'])) {
        // COM_applyFilter would strip special characters, e.g. quotes, so
        // we only strip HTML
        $fullname = strip_tags ($_POST['fullname']);
        $fullname = addslashes ($fullname);
    }

    // Note: In this case, we can trust the $uid variable to contain the new
    // account's uid.
    DB_query("UPDATE {$_TABLES['users']} SET email = '$email', homepage = '$homepage', fullname = '$fullname' WHERE uid = $uid");

    return true;
}

// Delete any records from custom tables you may have used
function CUSTOM_userDelete($uid)
{
    return true;
}

/* Called from users.php - when user is displaying a member profile.
 * This function can now return any extra fields that need to be shown.
 * Output is then replaced in {customfields} -- This variable needs to be added
 * to your templates
 * Template: path_layout/users/profile/profile.thtml
 */

function CUSTOM_userDisplay($uid)
{
    global $_CONF, $_TABLES;

    $var = "Value from custom table";
    $retval .= '<tr>
        <td align="right"><b>Custom Fields:</b></td>
        <td>'
. $var .'</td>
     </tr>'
;

    return $retval;
}


/* Function called when editing user profile. */
/* Called from usersettings.php - when user is eding their own profile  */
/* and from admin/user.php when admin is editing a member profile  */
/* This function can now return any extra fields that need to be shown for editing */
/* Output is then replaced in {customfields} -- This variable needs to be added to your templates */
/* User: path_layout/preferences/profile.thtml and Admin: path_layout/admin/user/edituser.thtml */

/* This example shows adding the Cookie Timeout setting and extra text field */
/* As noted: You need to add the {customfields} template variable. */
/* For the edituser.thtml - maybe it would be added about the {group_edit} variable. */

function CUSTOM_userEdit($uid)
{
    global $_CONF, $_TABLES;

    $var = "Value from custom table";
    $cookietimeout = DB_getitem($_TABLES['users'], 'cookietimeout', $uid);
    $selection = '<select name="cooktime">' . LB;
    $selection .= COM_optionList ($_TABLES['cookiecodes'], 'cc_value,cc_descr', $cookietimeout, 0);
    $selection .= '</select>';
    $retval .= '<tr>
        <td align="right">Remember user for:</td>
        <td>'
. $selection .'</td>
     </tr>'
;
    $retval .= '<tr>
        <td align="right"><b>Custom Fields:</b></td>
        <td><input type="text" name="custom1" size="50" value="'
. $var .'"></td>
     </tr>'
;
    $retval .= '<tr><td colspan="2"><hr></td></tr>';

    return $retval;
}

/* Function called when saving the user profile. */
/* This function can now update any extra fields  */
function CUSTOM_userSave($uid)
{
    global $_CONF, $_TABLES;

    $cooktime = 0;
    if (isset ($_POST['cooktime'])) {
        $cooktime = COM_applyFilter ($_POST['cooktime'], true);
        if ($cooktime < 0) {
            $cooktime = 0;
        }

        DB_query("UPDATE {$_TABLES['users']} SET cookietimeout = $cooktime WHERE uid = $uid");
    }
}


/**
* Main Form used for Custom membership when member is registering
*
* Note: Requires a file custom/memberdetail.thtml in every theme that is
*       installed on the site!
*
* @param    string  $msg    an error message to display or the word 'new'
* @return   string          HTML for the registration form
*
*/

function CUSTOM_userForm ($msg = '')
{
    global $_CONF, $_TABLES, $LANG04;

    if (!empty ($msg) && ($msg != 'new')) {
        $retval .= COM_startBlock($LANG04[21]) . $msg . COM_endBlock();
    }

    $post_url = $_CONF['site_url'] . '/users.php';
    $postmode = 'create';
    $submitbutton = '<input type="submit" value="Register Now!">';
    $message = "<blockquote style=\"padding-top:10px;\"><b>Please complete the application below. Once you have completed the application, click the Register Now! button and the application will be processed immediately.</b></blockquote>";

    $user_templates = new Template ($_CONF['path_layout'] . 'custom');
    $user_templates->set_file('memberdetail', 'memberdetail.thtml');
    $user_templates->set_var('site_url', $_CONF['site_url']);
    $user_templates->set_var('layout_url', $_CONF['layout_url']);
    $user_templates->set_var('post_url', $post_url);
    $user_templates->set_var('startblock', COM_startBlock("Custom Registration Example"));
    $user_templates->set_var('message', $message);

    $user_templates->set_var('USERNAME', $LANG04[2]);
    $user_templates->set_var('USERNAME_HELP', "Name to be used when accessing this site");
    $username = '';
    if (isset ($_POST['username'])) {
        $username = COM_applyFilter ($_POST['username']);
    }
    $user_templates->set_var('username', $username);

    $user_templates->set_var('EMAIL', $LANG04[5]);
    $user_templates->set_var('EMAIL_HELP', $LANG04[33]);
    $email = '';
    if (isset ($_POST['email'])) {
        $email = COM_applyFilter ($_POST['email']);
    }
    $user_templates->set_var('email', $email);

    $user_templates->set_var('EMAIL_CONF', $LANG04[124]);
    $user_templates->set_var('EMAIL_CONF_HELP', $LANG04[126]);
    $email_conf = '';
    if (isset ($_POST['email_conf'])) {
        $email_conf = COM_applyFilter ($_POST['email_conf']);
    }
    $user_templates->set_var('email_conf', $email_conf);

    $user_templates->set_var('FULLNAME', $LANG04[3]);
    $user_templates->set_var('FULLNAME_HELP', $LANG04[34]);
    $fullname = '';
    if (isset ($_POST['fullname'])) {
        $fullname = strip_tags ($_POST['fullname']);
    }
    $user_templates->set_var('fullname', $fullname);

    $user_templates->set_var('user_id', $user);
    $user_templates->set_var('postmode', $postmode);
    $user_templates->set_var('submitbutton', $submitbutton);
    $user_templates->set_var('endblock', COM_endBlock());
    $user_templates->parse('output', 'memberdetail');
    $retval .= $user_templates->finish($user_templates->get_var('output'));

    return $retval;
}
 



To this....


PHP Formatted Code

<?php


/* Create any new records in additional tables you may have added  */
/* Update any fields in the core GL tables for this user as needed */
/* Called when user is first created */
function custom_usercreate($uid) {
    global $_TABLES;

    $grad_year = COM_applyFilter($_POST['cust_gradyear'],true);
    $fullname  = COM_applyFilter($_POST['cust_fullname']);

    // Ensure all data is prepared correctly before inserts, quotes may need to be escaped with addslashes()
    DB_query("INSERT INTO {$_TABLES['localuserinfo']} (uid,grad_year) VALUES ('$uid', '$grad_year')");
    DB_query("UPDATE {$_TABLES['users']} SET fullname = '$fullname' WHERE uid='$uid'");
    return true;

}

// Delete user record from custom user info table
function custom_userdelete($uid) {
    global $_TABLES;

    DB_query("DELETE FROM {$_TABLES['localuserinfo']} WHERE uid='$uid'");
    return true;

}
/* Called from users.php - when user is displaying a member profile  */
/* This function will return any extra fields that need to be shown */
/* Output is then replaced in {customfields) -- This variable needs to be added to your templates */
/* Template: path_layout/users/profile/profile.thtml */

function custom_userdisplay($uid) {
    global $_CONF,$_TABLES;
    $grad_year = DB_getItem($_TABLES['localuserinfo'], "grad_year", "uid='$uid'");
    $fullname = DB_getItem($_TABLES['users'], "fullname", "uid='$uid'");
    $retval .= '<tr>
                    <td align="right"><b>Full Name:</b></td>
                    <td>'
. $fullname .'</td>
                 </tr>'
;
    $retval .= '<tr>
                    <td align="right"><b>Graduation Year:</b></td>
                    <td>'
. $grad_year .'</td>
                 </tr>'
;
    return $retval;

}


/* Function called when editing user profile. */
/* Called from usersettings.php - when user is eding their own profile  */
/* and from admin/user.php when admin is editing a member profile  */
/* This function will return any extra fields that need to be shown for editing */
/* Output is then replaced in {customfields} -- This variable needs to be added to your templates */
/* User: path_layout/preferences/profile.thtml and Admin: path_layout/admin/user/edituser.thtml */

function custom_useredit($uid) {
    global $_TABLES,$_CONF;

    $grad_year = DB_getItem($_TABLES['localuserinfo'], "grad_year", "uid='$uid'");
    $fullname = DB_getItem($_TABLES['users'], "fullname", "uid='$uid'");

    $retval .= '<tr>
        <td align="right"><b>Full Name:</b></td>
        <td><input type="text" name="cust_fullname" size="50" value="'
. $fullname .'"></td>
     </tr>'
;
    $retval .= '<tr>
        <td align="right"><b>Graduation Year:</b></td>
        <td><input type="text" name="cust_gradyear" size="5" maxlength="4" value="'
. $grad_year .'"></td>
     </tr>'
;
    $retval .= '<tr><td colspan="2"><hr></td></tr>';
   return $retval;
}

/* Function called when saving the user profile. */
function custom_usersave($uid) {
    global $_TABLES;

    $grad_year = COM_applyFilter($_POST['cust_gradyear'],true);
    $fullname  = COM_applyFilter($_POST['fullname']);

    DB_query("UPDATE {$_TABLES['users']} SET fullname='$fullname' WHERE uid='$uid'");
    if ($grad_year > 0) {
        DB_query("UPDATE {$_TABLES['localuserinfo']} SET grad_year='$grad_year' WHERE uid='$uid'");
    }

}


/* Main Form used for Custom membership when member is registering */
function custom_userform($uid="",$msg="") {
    global $_CONF,$_TABLES, $LANG04;

    if (!empty($msg)) {
        $retval .= COM_startBlock($LANG04[21]) . $msg . COM_endBlock();
    }

    $post_url = $_CONF['site_url']."/users.php";
    $postmode = "create";
    $submitbutton = '<input type="submit" value="Register Now!">';
    $passwd_input = "";
    $message = "<br><font color=black><b>Please complete the application below. Once you have completed the application, click the Submit button and the application will be processed immediately.</b></font>";
    $A=array();

    $user_templates = new Template ($_CONF['path_layout'] . 'custom');
    $user_templates->set_file('memberdetail', 'memberdetail.thtml');
    $user_templates->set_var('layout_url', $_CONF['layout_url']);
    $user_templates->set_var('post_url', $post_url);
    $user_templates->set_var('startblock', COM_startBlock("Custom Registration Example"));
    $user_templates->set_var('message', $message);    
    $user_templates->set_var('USERNAME', "Username");
    $user_templates->set_var('USERNAME_HELP', "Name to be used when accessing this site");
    $user_templates->set_var('username', $A['username']);
    $user_templates->set_var('passwd_input', $passwd_input);
    $user_templates->set_var('EMAIL', "Email Address");
    $user_templates->set_var('EMAIL_HELP', "Valid email address");
    $user_templates->set_var('email', $A['email']);
    $user_templates->set_var('FULLNAME', "Full Name");
    $user_templates->set_var('FULLNAME_HELP', "First and Last Name");
    $user_templates->set_var('fullname', $A['fullname']);
    $user_templates->set_var('GRADYEAR', "Graduation Year");
    $user_templates->set_var('GRADYEAR_HELP', "That big year!");
    $user_templates->set_var('grad_year', "");
    $user_templates->set_var('user_id', $user);
    $user_templates->set_var('postmode', $postmode);
    $user_templates->set_var('submitbutton', $submitbutton);
    $user_templates->set_var('endblock', COM_endBlock());
    $user_templates->parse('output', 'memberdetail');
    $retval .= $user_templates->finish($user_templates->get_var('output'));

    return $retval;
}


?>


Is that wrong? Because in front page in split view it shows a bunch of stuff on the design area where as it did not have anything there prior to pasting that code?

Thanks!


Status: offline

kilerb

Forum User
Regular Poster
Registered: 19/03/2008
Posts: 119
Hi... After playing with this all weekend, I am still totally stuck...

This is what I've discoverd so far...

I have been able to make a custom field appear, but it just does not work.

If I replace the lib-custom code like I menitoned in my previous post, it does not work at all. If I include the <?php at the begninning of the code I get a totally blank screen anywhere on my site. If I remove that, it does not even let me submit registration info. Just refreshes the registration screen and all the fields are blank again.

If I don't change my lib-custom page at all, it shows the fields and lets me enter the into, but it says "You have to enter the same email address in both fields!" even though there's only one field. So, I went into layout/proffesional/custom/memberdeatil.thtml and tried to add a conf_email field like this...

PHP Formatted Code
<!-- This is an example template file for the Custom User Registration Feature -->
<!-- To be located under theme/custom directory - Example professional/custom/memberdetail.thtml -->
{startblock}
{message}
<form action="{post_url}" method="post">
    <table border="0" cellspacing="0" cellpadding="2" width="400">
        <tr>
            <td align="right" style="text-align:left;vertical-align:middle;padding-left:10px;"><font color='#000000'><b>{USERNAME}</b></font><br><font color=#676767 size=1>{USERNAME_HELP}</font></td>
           <td align=left valign=middle><input type="text" name="username" size="25" maxlength="16" value="{username}"></td>
            <td><img src='/images/speck.gif' width=30 height=1></td>
        </tr>
        {passwd_input}
        <tr>
            <td align="right" style="text-align:left;vertical-align:middle;padding-left:10px;"><font color='#000000'><b>{EMAIL}</b></font><br><font color=#676767 size=1>{EMAIL_HELP}</font></td>
           <td align=left valign=middle><input type="text" name="email" size="25" maxlength="100" value="{email}"></td>
                <td><img src='/images/speck.gif' width=30 height=1></td>
        </tr>
        <tr>
            <td align="right" style="text-align:left;vertical-align:middle;padding-left:10px;"><font color='#000000'><b>{EMAIL_CONF}</b></font><br><font color=#676767 size=1>{EMAIL_HELP}</font></td>
           <td align=left valign=middle><input type="text" name="email" size="25" maxlength="100" value="{email_conf}"></td>
                <td><img src='/images/speck.gif' width=30 height=1></td>
        </tr>
        <tr>
            <td align="right" style="text-align:left;vertical-align:middle;padding-left:10px;"><font color='#000000'><b>{FULLNAME}</b></font><br><font color=#676767 size=1>{FULLNAME_HELP}</font></td>
           <td align=left valign=middle><input type="text" name="cust_fullname" size="25" maxlength="40" value="{fullname}"></td>
            <td><img src='/images/speck.gif' width=30 height=1></td>
           </tr>
        <tr>
            <td align="center" colspan="3"><input type="hidden" name="uid" value="{user_id}"><HR><BR>
            <input type="hidden" name="mode" value="text">{submitbutton}</td>
        </tr>
    </table>
</form>
{endblock}


it still says "You have to enter the same email address in both fields!" when I do put the same email in both the fields now. So, I now have no idea what's wrong. The lib-custom file remains unchanged right now due to the fact that it doesn't work at all with the changes from the lib-custom_code changes. I'm sure that's not helping things. Any help getting me going would be greatly appreciated. I'll turn the custom reg feature to false for now in my config.php.

By the way... I didn't do the steps involving mysql tables because I'm only trying to add the full name field and nothing more. I was under the impression from reading the instructions that this step was not necessary.

Thanks a lot
Brian

Status: offline

jmucchiello

Forum User
Full Member
Registered: 29/08/2005
Posts: 985
Quote by: kilerb

If I don't change my lib-custom page at all, it shows the fields and lets me enter the into, but it says "You have to enter the same email address in both fields!" even though there's only one field. So, I went into layout/proffesional/custom/memberdeatil.thtml and tried to add a conf_email field like this...

What theme are you using? In Geeklog 1.4.1 they added an email confirmation field to the registration form:
PHP Formatted Code

    <tr>
         <td class="alignright"><b>{lang_email}:</b></td>
         <td><input type="text" size="32" maxlength="96" name="email" value="{email}"></td>
     </tr>
     <tr>
         <td class="alignright"><b>{lang_email_conf}:</b></td>
         <td><input type="text" size="32" maxlength="96" name="email_conf" value="{email_conf}"></td>
     </tr>
 
Your theme appears to be missing this field.

Status: offline

kilerb

Forum User
Regular Poster
Registered: 19/03/2008
Posts: 119
Hi, I am using 1.4.1 and it does ask you to repeat the email address normally. When I turn the custom config option to false in config.php it asks for one and works perfectly. When adding a new field (attempting to add a new field I should say) the field for 2nd email was not there but it still said "You have to enter the same email address in both fields!" when you try to submit a new registration. (This is only when I don't make any adjustments to the lib-custom page, which I know you are supposed to make some changes. But like I mentioned above, when I make the changes the entire site does not work unless I remove the "<?php" from the beginning of the code that they give on that lib-custom_code page. When it's removed the site works, but registration does not.

On the lib-custom page, that is just supposed to be copied to the same area in my lib-custom.php page on my site right?

Thanks!
Brian

Status: offline

kilerb

Forum User
Regular Poster
Registered: 19/03/2008
Posts: 119
Blaine suggested I figure this out by asking more specific questions... So I'l start from the beginning steps.


If I am making only 1 new field and it is going to be "FULL NAME" is it true that I don't need to do steps 1 and 2 in the tutorial? I'll list them here.

Thanks!


PHP Formatted Code
1) Create the new table that is used for the extra user info. In this case, there is only the one new field "grad_year".
Assuming your Geeklog Database prefix is 'gl_' execute the following SQL.
If you have phpMyAdmin - select the database and enter the SQL below.


CREATE TABLE `gl_localuserinfo` (
  `uid` mediumint(8) NOT NULL default '0',
  `grad_year` varchar(4) NOT NULL default '',
  KEY `uid` (`uid`)
) TYPE=MyISAM;

2) Tell Geeklog about your new database.
Add the following line to system/lib-database after the other database table defintions.

$_TABLES['localuserinfo']   = $_DB_table_prefix . 'localuserinfo';

All times are EDT. The time is now 08:35 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content