The following works just fine:
$j('#first_name').val("JACK");
however...
I am having trouble retrieving #first_name from {$memberinfo['username']}; using javascript...
Buck
How to capture $memberinfo with Javascript
Re: How to capture $memberinfo with Javascript
You need to get the $memberinfo array first by calling the function getMemberInfo()
$memberInfo = getMemberInfo();
See here: https://bigprof.com/appgini/help/advanc ... Info-array
Just a warning as I'm not entirely sure what you're trying to achieve but javascript won't retrieve the $memberInfo array "on the fly" (while you are looking at an open record).
Depending on what you're after; If you are just wanting to enter a Username into a field on creation or update, you might be better off using one of AppGini's built in "Default" values (<%%creatorUsername%%> or <%%editorUsername%%>) or even a simple hook rather than javascript? Just a thought....
$memberInfo = getMemberInfo();
See here: https://bigprof.com/appgini/help/advanc ... Info-array
Just a warning as I'm not entirely sure what you're trying to achieve but javascript won't retrieve the $memberInfo array "on the fly" (while you are looking at an open record).
Depending on what you're after; If you are just wanting to enter a Username into a field on creation or update, you might be better off using one of AppGini's built in "Default" values (<%%creatorUsername%%> or <%%editorUsername%%>) or even a simple hook rather than javascript? Just a thought....
Re: How to capture $memberinfo with Javascript
peebee... my original intent was to have the user's name displayed, on the input screen, while they were inputting data... certainly not necessary and serves very little purpose. I have several fields that are filled in as soon as the form is loaded and I tho't it might be neat to have the user's name on the screen. It is a math application for students in the 8-12 range or so... they kinda like to see there name.
I have been using Appgini for about 10 years, but only for a database manager/file maintenance, and it works very well for that... only recently have I decided to use HOOKS. I am catching on, but a little confused when to use "$data(fields name)" or "$fieldname" or just "fieldname" or "#fieldname" etc.
I'll just keep pluggin' away... you and grimblefritz have been of big help, but I do not want to wear out my welcome.
Thanks,
Buck
I have been using Appgini for about 10 years, but only for a database manager/file maintenance, and it works very well for that... only recently have I decided to use HOOKS. I am catching on, but a little confused when to use "$data(fields name)" or "$fieldname" or just "fieldname" or "#fieldname" etc.
I'll just keep pluggin' away... you and grimblefritz have been of big help, but I do not want to wear out my welcome.
Thanks,
Buck
-
- AppGini Super Hero
- Posts: 336
- Joined: 2015-12-23 16:52
Re: How to capture $memberinfo with Javascript
Buck,
It helps to bear in mind the nature of web apps. There's server component and a client component, and specific roles and limitations for each.
Just keep in mind that PHP hooks run on the web server and have access to the sql database and the various vars/arrays/objects defined in PHP. That all runs as the page is being constructed, or after the page is submitted (saved.) In that regard, the PHP elements are one-shot, in that they run to construct the page or to parse the page, but don't do anything interactively while the page is being used.
Javascript runs in the browser and can only deal with the page after it's been constructed by the server and sent to the browser to be rendered. It can also interact with the page while it's being used. It cannot read or write the sql database. (Unless using ajax, but then that's not exactly javascript, but basically like a separate page request/generate/send/parse event.)
Keeping in mind WHEN you need to create an action, will help you decide WHERE to code it. And that will determine HOW things are named and accessed, etc.
And, when in doubt, ask. You might not the only one wondering, so an answer to you could be an answer to several.
It helps to bear in mind the nature of web apps. There's server component and a client component, and specific roles and limitations for each.
Just keep in mind that PHP hooks run on the web server and have access to the sql database and the various vars/arrays/objects defined in PHP. That all runs as the page is being constructed, or after the page is submitted (saved.) In that regard, the PHP elements are one-shot, in that they run to construct the page or to parse the page, but don't do anything interactively while the page is being used.
Javascript runs in the browser and can only deal with the page after it's been constructed by the server and sent to the browser to be rendered. It can also interact with the page while it's being used. It cannot read or write the sql database. (Unless using ajax, but then that's not exactly javascript, but basically like a separate page request/generate/send/parse event.)
Keeping in mind WHEN you need to create an action, will help you decide WHERE to code it. And that will determine HOW things are named and accessed, etc.
And, when in doubt, ask. You might not the only one wondering, so an answer to you could be an answer to several.
-
- AppGini Super Hero
- Posts: 336
- Joined: 2015-12-23 16:52
Re: How to capture $memberinfo with Javascript
Also, if it makes you feel any better, I've also had AppGini for years and used it only for basic database management. But with the recent releases I've found it acceptable for basic applications, and with fewer demands on my time over the last year or two I've had more time to delve into hooks.
Because I don't like to be orphaned when new versions make major changes in core code, I try to do everything custom via hooks. That way, if AppGini 5.x or 6.x makes serious changes in the core, I don't have a bunch of hacks to port forward. At worst, just a few hooks to massage. I'd rather code a bit more in hooks, perhaps less elegantly than if I modified the core, than expose myself to being locked out of upgrades due to the cost of porting core code modifications.
My $0.02 fwiw
Because I don't like to be orphaned when new versions make major changes in core code, I try to do everything custom via hooks. That way, if AppGini 5.x or 6.x makes serious changes in the core, I don't have a bunch of hacks to port forward. At worst, just a few hooks to massage. I'd rather code a bit more in hooks, perhaps less elegantly than if I modified the core, than expose myself to being locked out of upgrades due to the cost of porting core code modifications.
My $0.02 fwiw
-
- AppGini Super Hero
- Posts: 336
- Joined: 2015-12-23 16:52
Re: How to capture $memberinfo with Javascript
Oh, and if you absolutely must have $memberinfo available in javascript, here's one way to do it.
Or, rather than expose all the details in memberinfo, since what you want is the username...
1. In tablename.php function tablename-dv(), inject a hidden field with id=membername and value=name (name coming from $memberinfo)
2. In tablename-dv.js use jquery to get the membername, as in: membername=$j('#membername').val();
You could, if you wanted, then use jquery to delete #membername so it's not seen if someone views page source. Not foolproof, but fools most.
Or, rather than expose all the details in memberinfo, since what you want is the username...
1. In tablename.php function tablename-dv(), inject a hidden field with id=membername and value=name (name coming from $memberinfo)
2. In tablename-dv.js use jquery to get the membername, as in: membername=$j('#membername').val();
You could, if you wanted, then use jquery to delete #membername so it's not seen if someone views page source. Not foolproof, but fools most.
Re: How to capture $memberinfo with Javascript
grimble,
Good synopsis... and thank you for taking the time
Buck
Good synopsis... and thank you for taking the time
Buck
Re: How to capture $memberinfo with Javascript
Fortunately for you Buck, I had reason to grab the $memberInfo to inject into some javascript in a previous project I was working on. I used AJAX and JSON.
Everything you need to know to achieve what you're after should be contained in this post: http://forums.appgini.com/phpbb/viewtop ... Javascript
Good luck
Everything you need to know to achieve what you're after should be contained in this post: http://forums.appgini.com/phpbb/viewtop ... Javascript
Good luck
Re: How to capture $memberinfo with Javascript
peebee... thank you, I will take a look.
Buck
Buck
Re: How to capture $memberinfo with Javascript
Anyone could offer help here? I need to parse the php variable to the javascript in js file as follows:
//table-tv.js for mass update. Want to replace the selection drop down list with a php return value
//js code (Don't know which file to place the js code as it contains php script)
// php code - prepare the list for drop down value (Dunno place at which php file)
//table-tv.js for mass update. Want to replace the selection drop down list with a php return value
Code: Select all
// part of the code//
/* prepare select2 drop-down inside modal */
$j('#mass-update-new-value-modal').on('shown.bs.modal', function () {
$j("#mass-update-new-value").select2({
width: '100%',
formatNoMatches: function(term){ return massUpdateTranslation.noMatches; },
minimumResultsForSearch: 5,
loadMorePadding: 200,
data: [{"id":"user3","text":"user3"}], //Replacing value with js variable eg. repvalue
escapeMarkup: function(str){ return str; }
}).select2('focus');
});
Code: Select all
var repvalue = "<?php echo json_encode($repValue); ?>"
Code: Select all
$replist = array("user1","user2");
$repValue = [];
foreach ($replist as $a){
$repValue[] = array("id" => $a,"text" => $a);
}
$fixed = array("id" => "user3","text" => "user3");
$repValue[] = $fixed; //will output [{"id":"user1","text":"user1"},{"id":"user2","text":"user2"},{"id":"user3","text":"user3"}]