Passing Username to a form field

I’ve read here using [usr_name] or something in a database insert/edit value within the field editor would pass the logged in username to that field however its not working as expected, for example:

I have a form with a “Name” Field I would like the logged in users details captured in (displayed on the form as a name field rather than a editable field) I have the security module enabled and configured yet am unable to workout the var used to display the correct information.

[QUOTE=w33tbix;37322]I’ve read here using [usr_name] or something in a database insert/edit value within the field editor would pass the logged in username to that field however its not working as expected, for example:

I have a form with a “Name” Field I would like the logged in users details captured in (displayed on the form as a name field rather than a editable field) I have the security module enabled and configured yet am unable to workout the var used to display the correct information.[/QUOTE]

Don’t expect that everything is there by default. The security module is a generated php application (from a wizzard) and it’s ‘just a program’. So you need to go to the code and look if the variable is retrieved, and if so saved in a global variable. If not (and I think it’s not) then you have to modify the sql to retrieve the value and add it to the spot where the globals are stored. Please keep the [] notation, I know that the generated module is still using a deprecated macro.

ok how would one do that??? crikey you would think this would be easier than it currently is, I’m learning slowly but seems SC over complicates what should be fairly basic options imo… coming over from PHPRunner it’s a massive change.

Just go to the security section, open your login application and look at the code. Go to the onvalidate event. For sure you can find the spot where the user is checked against the sc_users table, add the userfield and assign the retrieved user to a global variable you declare yourself. Really this can’t be too hard, unless you are new to php too. But if you know phpRunner, then this should be a piece of cake. But I looked into the code, and it appears that the variable name would be [usr_name]


$slogin = sc_sql_injection({login});
$spswd = sc_sql_injection(md5({pswd}));

$sql = "SELECT 
		priv_admin,
		active, 
		name, 
		email 
	      FROM sec_users 
	      WHERE login = $slogin
		AND pswd = ".$spswd."";
	
sc_lookup(rs, $sql);
	
if(count({rs}) == 0)
{
	sc_log_add('login Fail', {lang_login_fail} . {login});
	sc_error_message({lang_error_login});
	sc_error_exit();
}
else if({rs[0][1]} == 'Y')
{
	$usr_login		= {login};
	$usr_priv_admin 	= ({rs[0][0]} == 'Y') ? TRUE : FALSE;
	$usr_name		= {rs[0][2]};
	$usr_email		= {rs[0][3]};
	sc_set_global($usr_login);
	sc_set_global($usr_priv_admin);
	sc_set_global($usr_name);
	sc_set_global($usr_email);
}
else
{
	sc_error_message({lang_error_not_active});
	sc_error_exit();
}

I am new to everything, php included well i’ve played with it for years but nothing too in depth.

Ok I found the above and mine is the same sc_set_global($usr_name); so thefore [usr_name] should work right I already had this part figured out but the rest is what confuses me.

phprunner and Dreamweaver for that mater had this as a selectable function without the need to code anything hence the reason it should be easier than this, yes SC does more but is it really “The best and most efficient web development environment”

Ok it’s working, for some reason it wasn’t working as a text field input to the database but is when it’s set to label field…

update: figured it out, I forgot to add it to initial value so it would show blank but I assume it would save the correct one once commiting the data to the database??? Like I said still learning