Page 1 of 1

how to get member username with js?

Posted: 2019-05-31 18:11
by D Oliveira
hello, how to get member username with js? if you use the automatic value built in appgini whenever you call $j.val() it returns "" and I need it to return the username value, any ideas?

Thank you.

Re: how to get member username with js?

Posted: 2019-05-31 21:49
by jsetzer
If you use a field with that automatic value it should become a static control div and not an input. This means you cannot use .val() method. Try .text() instead:

var user = $j("created_by").text();

Regards,
Jan

Re: how to get member username with js?

Posted: 2019-05-31 22:02
by D Oliveira
jsetzer wrote:
2019-05-31 21:49
If you use a field with that automatic value it should become a static control div and not an input. This means you cannot use .val() method. Try .text() instead:

var user = $j("created_by").text();

Regards,
Jan

you sir are a genius, well deserved title/badge. one more question, how do you verify that the user name matches the text extracted from that field?

That reference should be accessible to all appgini users like the select2 tweaks and .reload features. thank you!

Re: how to get member username with js?

Posted: 2019-05-31 23:01
by D Oliveira
user udayvatturi posted somewhere the solution, here it is:

Code: Select all


Ajax Call

var url1="getMemberInfo.php"; 
jQuery.ajax({
url: url1,
dataType: 'json',
success:function(response){
//alert(response); //display memberinfo['username']

if( $j('#createdby').text() == response ){
			console.log('here')
								
}
}

});

getMemberInfo.php
<?php
$curr_dir = dirname(__FILE__);
include("{$curr_dir}/defaultLang.php");
include("{$curr_dir}/language.php");
include("{$curr_dir}/lib.php");

$mi = getMemberInfo();
echo json_encode($mi['username']);
?>


Re: how to get member username with js?

Posted: 2019-06-01 01:10
by D Oliveira
D Oliveira wrote:
2019-05-31 23:01
user udayvatturi posted somewhere the solution, here it is:

Code: Select all


Ajax Call

var url1="getMemberInfo.php"; 
jQuery.ajax({
url: url1,
dataType: 'json',
success:function(response){
//alert(response); //display memberinfo['username']

if( $j('#createdby').text() == response ){
			console.log('here')
								
}
}

});

getMemberInfo.php
<?php
$curr_dir = dirname(__FILE__);
include("{$curr_dir}/defaultLang.php");
include("{$curr_dir}/language.php");
include("{$curr_dir}/lib.php");

$mi = getMemberInfo();
echo json_encode($mi['username']);
?>

also you wanna add that to your tablename-dv.js if you're trying to accomplish the same:

Code: Select all

jQuery('#update').hide();

//or 

jQuery('#update').show();

Re: how to get member username with js?

Posted: 2024-04-04 19:37
by xbox2007
hello
i have other way dont know if can be fine or not

this code to show current login Group , and can change to to show current user

i add this code infooter-extras.php

Code: Select all

<?php 
	$mi = getMemberInfo();
?>
<script>
	var AdminUser = "<?php echo $mi['group']; ?>" ;	
	//alert(AdminUser);
</script>
and add this code on table-dv.js to make sure its working

Code: Select all

	alert(AdminUser);