1
DanDigital
Help! - adding fields to registration form
  • 2007/9/27 15:46

  • DanDigital

  • Just popping in

  • Posts: 1

  • Since: 2007/9/27


Hi,

I'm adding two new fields to the registration form, a gender selector and location seletor and could use some help fixing bugs...

The gender selector is cloned from formradioyn.php and displays fine but won't post to the DB (i have created an int field called 'user_type' to recieve it)

The location selector uses the existing 'user_from' DB field but I want to use the formselectcountry.php drop down. Again, this displays fine but only enters a zero into the DB.

Have spent hours on this and can't seem to figure it out. Any help wold be really appreciated!

Changed code snippets for register.php and registerform.php are below.

Thanks,
Dan

register.php

from line 117

$op = !isset($_POST['op']) ? 'register' : $_POST['op'];
$uname = isset($_POST['uname']) ? $myts->stripSlashesGPC($_POST['uname']) : '';
$email = isset($_POST['email']) ? trim($myts->stripSlashesGPC($_POST['email'])) : '';
$name = isset($_POST['name']) ? $myts->stripSlashesGPC($_POST['name']) : '';
$url = isset($_POST['url']) ? trim($myts->stripSlashesGPC($_POST['url'])) : '';
$pass = isset($_POST['pass']) ? $myts->stripSlashesGPC($_POST['pass']) : '';
$vpass = isset($_POST['vpass']) ? $myts->stripSlashesGPC($_POST['vpass']) : '';
$user_from = isset($_POST['user_from']) ? intval($_POST['user_from']) : '';
$timezone_offset = isset($_POST['timezone_offset']) ? intval($_POST['timezone_offset']) : $xoopsConfig['default_TZ'];
$user_type = (isset($_POST['user_type']) && intval($_POST['user_type'])) ? 1 : 0;
$user_viewemail = (isset($_POST['user_viewemail']) && intval($_POST['user_viewemail'])) ? 1 : 0;
$user_mailok = (isset($_POST['user_mailok']) && intval($_POST['user_mailok'])) ? 1 : 0;
$agree_disc = (isset($_POST['agree_disc']) && intval($_POST['agree_disc'])) ? 1 : 0;

from line 155

echo _US_TIMEZONE.": $f_timezone
";
echo "


";
echo "








and from line 183

$member_handler =& xoops_gethandler('member');
$newuser =& $member_handler->createUser();
$newuser->setVar('user_viewemail',$user_viewemail, true);
$newuser->setVar('uname', $uname, true);
$newuser->setVar('email', $email, true);
$newuser->setVar('name', $name, true);
$newuser->setVar('user_type', $user_type, true);
if ($url != '') {
$newuser->setVar('url', formatURL($url), true);
}
$newuser->setVar('user_avatar','blank.gif', true);
$actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8);
$newuser->setVar('actkey', $actkey, true);
$newuser->setVar('pass', md5($pass), true);
$newuser->setVar('user_from', $user_from, true);
$newuser->setVar('timezone_offset', $timezone_offset, true);
$newuser->setVar('user_regdate', time(), true);
$newuser->setVar('uorder',$xoopsConfig['com_order'], true);
$newuser->setVar('umode',$xoopsConfig['com_mode'], true);
$newuser->setVar('user_mailok',$user_mailok, true);


registerform.php

if (!defined("XOOPS_ROOT_PATH")) {
die("XOOPS root path not defined");
}
include_once XOOPS_ROOT_PATH."/class/xoopslists.php";
include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php";


$email_tray = new XoopsFormElementTray(_US_EMAIL, "
");
$email_text = new XoopsFormText("", "email", 25, 60, $myts->htmlSpecialChars($email));
$email_option = new XoopsFormCheckBox("", "user_viewemail", $user_viewemail);
$email_option->addOption(1, _US_ALLOWVIEWEMAIL);
$email_tray->addElement($email_text, true);
$email_tray->addElement($email_option);

//$avatar_select = new XoopsFormSelect("", "user_avatar", $user_avatar);
//$avatar_array =& XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH."/images/avatar/");
//$avatar_select->addOptionArray($avatar_array);
//$a_dirlist =& XoopsLists::getDirListAsArray(XOOPS_ROOT_PATH."/images/avatar/");
//$a_dir_labels = array();
//$a_count = 0;
//$a_dir_link = "XOOPS";
//$a_count = $a_count + count($avatar_array);
//$a_dir_labels[] = new XoopsFormLabel("", $a_dir_link);
//foreach ($a_dirlist as $a_dir) {
// if ( $a_dir == "users" ) {
// continue;
// }
// $avatars_array =& XoopsLists::getImgListAsArray(XOOPS_ROOT_PATH."/images/avatar/".$a_dir."/", $a_dir."/");
// $avatar_select->addOptionArray($avatars_array);
// $a_dir_link = "".$a_dir."";
// $a_dir_labels[] = new XoopsFormLabel("", $a_dir_link);
// $a_count = $a_count + count($avatars_array);
//}
//$avatar_select->setExtra("onchange='showImgSelected(\"avatar\", \"user_avatar\", \"images/avatar\", \"\", \"".XOOPS_URL."\")'");
//$avatar_label = new XoopsFormLabel("", "");
//$avatar_tray = new XoopsFormElementTray(_US_AVATAR, " ");
//$avatar_tray->addElement($avatar_select);
//$avatar_tray->addElement($avatar_label);
//foreach ($a_dir_labels as $a_dir_label) {
// $avatar_tray->addElement($a_dir_label);
//}

$reg_form = new XoopsThemeForm(_US_USERREG, "userinfo", "register.php", "post", true);
$uname_size = $xoopsConfigUser['maxuname'] < 25 ? $xoopsConfigUser['maxuname'] : 25;
$reg_form->addElement(new XoopsFormText(_US_NICKNAME, "uname", $uname_size, $uname_size, $myts->htmlSpecialChars($uname)), true);
$reg_form->addElement($email_tray);
$reg_form->addElement(new XoopsFormText(_US_REALNAME, "name", 30, 60, $name), true);
$reg_form->addElement(new XoopsFormPassword(_US_PASSWORD, "pass", 10, 32, $myts->htmlSpecialChars($pass)), true);
$reg_form->addElement(new XoopsFormPassword(_US_VERIFYPASS, "vpass", 10, 32, $myts->htmlSpecialChars($vpass)), true);
$reg_form->addElement(new XoopsFormRadioGender(_US_SEX, "user_type", $user_type));
$reg_form->addElement(new XoopsFormText(_US_WEBSITE, "url", 25, 255, $myts->htmlSpecialChars($url)));
$reg_form->addElement(new XoopsFormSelectCountry(_US_LOCATION, "user_from", $user_from));
$tzselected = ($timezone_offset != "") ? $timezone_offset : $xoopsConfig['default_TZ'];
$reg_form->addElement(new XoopsFormSelectTimezone(_US_TIMEZONE, "timezone_offset", $tzselected));
//$reg_form->addElement($avatar_tray);
$reg_form->addElement(new XoopsFormRadioYN(_US_MAILOK, 'user_mailok', $user_mailok));
if ($xoopsConfigUser['reg_dispdsclmr'] != 0 && $xoopsConfigUser['reg_disclaimer'] != '') {
$disc_tray = new XoopsFormElementTray(_US_DISCLAIMER, '
');
$disc_text = new XoopsFormTextarea('', 'disclaimer', $xoopsConfigUser['reg_disclaimer'], 8);
$disc_text->setExtra('readonly="readonly"');
$disc_tray->addElement($disc_text);
$agree_chk = new XoopsFormCheckBox('', 'agree_disc', $agree_disc);
$agree_chk->addOption(1, _US_IAGREE);
$eltname = $agree_chk->getName();
$eltmsg = str_replace('"', '\"', stripslashes( sprintf( _FORM_ENTER, _US_IAGREE ) ) );
$agree_chk->customValidationCode[] = "if ( myform.{$eltname}.checked == false ) { window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }";
$disc_tray->addElement($agree_chk, true);
$reg_form->addElement($disc_tray);
}
$reg_form->addElement(new XoopsFormHidden("op", "newuser"));
$reg_form->addElement(new XoopsFormButton("", "submit", _US_SUBMIT, "submit"));
?>

2
vaughan
Re: Help! - adding fields to registration form
  • 2007/9/27 16:35

  • vaughan

  • Friend of XOOPS

  • Posts: 680

  • Since: 2005/11/26


use smartprofile from smartfactory, but read the forum as there's a later version posted in 1 of the threads.

it'll save the need for editing the core as such.

but as for your above edits.

you forgot to edit kernel/user.php

your extra fields need adding to

function XoopsUser() (around line 70) you'll see the format in which to enter.

then you need to create a function similar to in format >

function user_from($format="S")
{
return $this->getVar("user_from", $format);
}

again you'll find this in kernel/user.php around 286 onwards.

then you need to add your fields to function insert() (around line 526) don't forget the %s or %u

alternatively do a search for XOOPS profile hack, it's not up2date anymore, and i no longer support it, but there's some good discussion with how to edit and add things in the forum thread..

Login

Who's Online

330 user(s) are online (96 user(s) are browsing Support Forums)


Members: 0


Guests: 330


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Oct 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits