John Kennedy Posted April 2, 2020 Share Posted April 2, 2020 (edited) Looking to display a few read-only custom fields in client area. I tried putting the fields in as per the documentation, but it doesn't seem to work. I seem to be missing something, but can't figure out what exactly. Edited April 2, 2020 by John Kennedy 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 2, 2020 Share Posted April 2, 2020 client custom fields would be automatically displayed in clientareadetails.tpl - though they would need tweaking, e.g hook / template edit, to make them readonly. are you trying to do this on that page, or on another (customerareadetails.tpl doesn't exist by default). 0 Quote Link to comment Share on other sites More sharing options...
John Kennedy Posted April 2, 2020 Author Share Posted April 2, 2020 (edited) I know they show up automatically when added but, when done that way, they can be edited. I wan't to change the template so it only shows a set of certain fields as text instead of input boxes. This is the template I'm talking about: # ls -liah | grep details -rw-r--r-- 1 whmcs whmcs 7126 Apr 2 16:47 clientareadetails.tpl Edit: I think I know what I'm doing wrong. This template is used when editing the customer profile. Guess, I'll keep digging, maybe I just need to use a different area to show the fields. Edited April 2, 2020 by John Kennedy 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 2, 2020 Share Posted April 2, 2020 (edited) 23 minutes ago, John Kennedy said: I know they show up automatically when added but, when done that way, they can be edited. I wan't to change the template so it only shows a set of certain fields as text instead of input boxes. it would be better to change the array rather than the template - though you could do either... but the html of these custom fields is really in the array and not the template. ultimately, it would be a variation on the hook below... ... and for simplicity, i'm assuming these are text fields that you want to lock.. <?php /** * Modify Custom Client Fields on Profile Page * @author brian! */ function modify_custom_client_fields_hook($vars) { if ($vars['templatefile'] == "clientareadetails") { $oldkey = array(">"); $newkey = array(" readonly >"); $ccfids = array(42,45); foreach ($vars['customfields'] as $ccf => $value) { if (in_array($value['id'],$ccfids)) { $vars['customfields'][$ccf]['input'] = str_replace($oldkey,$newkey,$value['input']); } } return array("customfields" => $vars['customfields']); } } add_hook("ClientAreaPage",1,"modify_custom_client_fields_hook"); the only line you should need to change is the array of customfield ids in $ccfids... you can get the ids by viewing the source of the page in the browser. Edited April 2, 2020 by brian! 0 Quote Link to comment Share on other sites More sharing options...
John Kennedy Posted April 2, 2020 Author Share Posted April 2, 2020 (edited) Looks like I'll need to modify/add a few more things before I can have these custom fields displayed where I want them. Thanks for the info. Edited April 2, 2020 by John Kennedy 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 2, 2020 Share Posted April 2, 2020 12 minutes ago, John Kennedy said: Looks like I'll need to modify/add a few more things before I can have these custom fields displayed where I want them. if there are customfields that you don't want to show, you can just remove them from the array. 0 Quote Link to comment Share on other sites More sharing options...
John Kennedy Posted April 2, 2020 Author Share Posted April 2, 2020 5 minutes ago, brian! said: if there are customfields that you don't want to show, you can just remove them from the array. I do want them to show up in the admin area, so I made them "Admin only". From what I understand, the hook will only affect listed CFs. So I don't make them Admin only and add them to the hook array for them to show up, but be read only? I was thinking of taking it a bit further actually - one of the fields is a unique link that I add directly into the database via a synch script, and I want that to be clickable on the primary sidebar. But this will do for now. I already checked one of your older post for the sidebar thing: 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 2, 2020 Share Posted April 2, 2020 1 minute ago, John Kennedy said: I do want them to show up in the admin area, so I made them "Admin only". all custom fields will appear in the admin area - by making them admin only, they won't show up in the client area, e.g they won't be in the array you're trying to manipulate. 3 minutes ago, John Kennedy said: From what I understand, the hook will only affect listed CFs. yes... if you really had to, you could make them admin only, and then query the database to add them to this array.... but you shouldn't really need to do that. 4 minutes ago, John Kennedy said: So I don't make them Admin only and add them to the hook array for them to show up, but be read only? yes - don't make them admin only; they will then be available to the array... and if they're text fields and in the list of CCF ids, then the hook should make them readonly. 8 minutes ago, John Kennedy said: I was thinking of taking it a bit further actually - one of the fields is a unique link that I add directly into the database via a synch script, and I want that to be clickable on the primary sidebar. But this will do for now. I already checked one of your older post for the sidebar thing: I shudder when I see my hooks from three years ago. 😨 what you want to do is doable and that hook would be a good starting point.... in your case, you might find it easier to get the ccf value from the database, and then wrap that value in an href - but if you run into any obstacles with it, let me know. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 3, 2020 Share Posted April 3, 2020 I should add that you probably don't need about 75% of that sidebar hook code if all you want to do is add a customfield link to the end of the existing details. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.