Convert an Input value to a placeholder

Hi Bruno,

  • I have a few docs. Each of that docs has a bunch auf TVs.

  • With pdoResources I generate a view with all that. Each page is therefor a “pdoresources-item” (so to speak)

  • Each of that Item has some Infos from the TVs and so an. And each Item has a Button that trigers a modal. (I only have one Modal in the Template).

  • Then I have users. A user has a custom field that contains eg.: “test001”.

  • The user can klick on the Button and the modal shows up. In the modal, a query should then be made as to whether the clicked “pdoresources-item” (a specific TV contains a value) and the user’s custom field match. If so, specific information is displayed (some TVs of the cklicked “pdoresources-item”) . If not another information is displayed.

How confidential is the information that is displayed?

It may be easier to load all the data with the initial page request and then show the correct information with javascript without the need to load more data with AJAX.

1 Like

How confidential is the information that is displayed?
It may be easier to load all the data with the initial page request and then show the correct information with javascript without the need to load more data with AJAX.

Let me explain a litte bit more:

  • The Pages with the TV are project-descriptions. The project-owner declared by which type of user he would like to be contacted (This Info come from a TV with a String like (e.g.) “Developer, PR-Professional, Comic-Artist”)
  • On the other hand the user have an custom field wich declares he is a (e.g.) “Developer”, or “PR-Professional” or “Comic-Artist”.
  • If the User click on the “Get Contact” button, the Modal show up an give the contact-information when the contact-type match. Otherwise he gets an notice that he is not allowed to get the contact-informations.

My thougt was to have only one Modal inside the template. But with that it is difficult to get the informations from the clicked item. (as we see).
As I see it now, it is actually easier (like you said too) that each item has its own modal and I can read the TVs directly and only query whether the contact type matches or not.
All of that directly in the tpl chunk of pdoressources.

Are these registered users in MODX? Do they have their own entry in the modUser table?


It seems to me, that the better user experience would be to not show the “Get Contact” button at all, if the user isn’t allowed to see the information.

Yes.

It seems to me, that the better user experience would be to not show the “Get Contact” button at all, if the user isn’t allowed to see the information.

Interesting. Yes that could be better.

The thing is: If the User see the contact-data, (Open the modal) there must be send an email to the admin.
Like: User XYZ requested the contact-data of Project XXX.

So if your users are logged in to MODX, you don’t have to send user-data back from the frontend to the server. The information about the current user should be available with $modx->user.


An “AJAX-endpoint” that returns the contact information and sends an email is probably still the best option.

Yes, I know. That is not the problem. But I need the info from the TV of the current (clicked) item.
So, yes I thing, that an AJAX-endpoint ist the beste way, too.

You can load the TV value directly with code like this

$resourceId = 1; // ID of the resource
$tvId = 2; // ID of the template variable
$tv = $modx->getObject('modTemplateVarResource', ['contentid' => $resourceId, 'tmplvarid' => $tvId]);
if ($tv) { // TV exists
    $tv_value = $tv->get('value');
}

or get it from the resource with code like this

$resourceId = 1; // ID of the resource
$r = $modx->getObject('modResource', $resourceId);
if ($r) { // resource exists
    $tv_value = $r->getTVValue('myTV');
}