Problems, need help? Have a tip or advice? Post it here.
7 posts Page 1 of 1
I am looking for a way to make an input field on a databound form readonly. Something similar as the common HTML input tag supports: <input name="readonly-field" value="you cannot change this" readonly>

My use case for this is as follows. Through their profile the registered users (club members) can now view and edit their name and email address. We would like to extend this and allow them to see all data we've registered of them: address, bank account, date of birth, and so on. Some of those fields should be viewable but not be adaptable for the user (date of birth, bankaccount) while others should be viewable and adaptable (address).

The rationale behind this is to make our club more self service and make the task of the back office easier, but also to fulfill GDPR obligations: GDPR obligates us to provide club members insight in all the personal data we've registered of them.

Is this possible?
"I have never tried that before, so I think I should definitely be able to do that" - Pippi Longstocking
Observation: if I enter readonly='1' in the cms:input tag, then the field will appear as read-only in the form, however it will still be editable.

Code: Select all
<cms:input class='form-control' name='date-of-birth' type='bound' readonly='1'/>


Is this a bug, an undocumented feature, or an undesired side-effect?
"I have never tried that before, so I think I should definitely be able to do that" - Pippi Longstocking
brightwolf wrote: Is this a bug, an undocumented feature, or an undesired side-effect?

It is a documented feature. 'Bound' inputs are limited by their original editable's definition. I think you are running circles wrongway, instead use regular inputs and maybe even simplest <cms:show /> since you need only to display data.
I did try cms:show but it does not work for my own field, like "bankrekeningnr" (bank account number).

Here is what I tried:
Code: Select all
bank: <cms:show bankrekeningnr /><br /><br />
bank input html: <input class=form-control type=text value="<cms:show bankrekeningnr />" readonly><br /><br />
bank input couch: <cms:input class='form-control' name='bankrekeningnr' type='bound' required='1' /><br /><br />
bankinput couch 2: <cms:input class='form-control' name='bankrekeningnr' type='bound' required='1' readonly /><br /><br />
bankinput couch 3: <cms:input class='form-control' name='bankrekeningnr' type='bound' required='1' readonly='1' /><br /><br />


The result is that 'bank' and 'bank input html' are empty (nothing displayed), but the second as an empty input field.
For 'bank input couch 1' a normal populated input field is shown (as expected) but I want a read only field. For 'bank input couch 2' it is the same and even for 'bank input couch 3' it is the same. You can see the results in the screenshot which I posted in my Dropbox: https://www.dropbox.com/s/ijeerkprne1a0ax/Screenshot%202019-03-19%2022.07.30.png?dl=0

For now I solved it by creating a query on the database to fetch the field I want to show. I then show that field in using a normal html input tag, you can see the expected result in the very last line in the above mentioned screenshot (note that the get_field_value also masquerades part of the bankaccount nr for privacy reasons):

Code: Select all
<cms:php>
[..]
$value = get_field_value($dbservername, $dbusername, $dbpassword, $dbname, $dbprefix,"<cms:show k_user_name />","bankrekeningnr");
echo '<input class=form-control type=text value=' . $value . ' readonly>';
[..]
</cms:php>
"I have never tried that before, so I think I should definitely be able to do that" - Pippi Longstocking
I have debugged a bit further and come to the conclusion that I cannot reach the editable fields of the extended users template since I am trying to reach them from a different page, being profile.php. The editable fields are configured in users/index.php. At run-time couch will try to reach the field from the current template, and the field is not stored there. In that sense extended users still seems to be a hack, albeit a nice and handy one, but it doesn't seem to completely fit into couch.

I am now trying to use get_custom_field for this... not succeeding yet with extended users:

<cms:get_custom_field 'soort' masterpage='users/index.php' />
<cms:get_custom_field 'soort' masterpage='../users/index.php' />
<cms:get_custom_field 'soort' masterpage='/users/index.php' />
all yield nothing.

If I try something similar with a "normal" template, a field is fetched and displayed. Maybe I am doing something wrong?

My only way out at this moment is using my custom made php query command.
Is there something else I could do to make this more standard?
"I have never tried that before, so I think I should definitely be able to do that" - Pippi Longstocking
@brightwolf, the extended users template is just a regular clonable Couch template and so everything you can do with other Couch templates, you can do with it too.

Coming to your specific problem -
Code: Select all
<cms:get_custom_field 'soort' masterpage='users/index.php' />

in the code above, specifying only the template name will not suffice since we are dealing with a clonable template - we need also further specify which cloned page the data is to be fetched from.

From Couch v2.1 <cms:get_field> has supplanted <cms:get_custom_field> (please see viewtopic.php?f=5&t=11105 for examples) so I'll use the new tag -

Try using the following on any template and you should be able to fetch the 'soort' field from your user extended template
Code: Select all
<cms:get_field 'soort' masterpage=k_user_template id=k_user_id />

Notice how I am also specifying the cloned page using the 'id' param.

Hope this helps.
Thanks a ton, KK. This *does* work. My misunderstanding was indeed the template name and how to reference the id within it. Also, I did not know this new tag. In that sense it is not a hack and does not seem to be one either, instead it seems to be a matter of documentation. For that I may be able to invest some time in the near future (after I finished the recent changes to the website).
"I have never tried that before, so I think I should definitely be able to do that" - Pippi Longstocking
7 posts Page 1 of 1
cron