Jump to content

Displaying custom fields on clientareadetails.tpl


Recommended Posts

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).

Link to comment
Share on other sites

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 by John Kennedy
Link to comment
Share on other sites

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.

T3wKVh4.png

Edited by brian!
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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: 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated