Jump to content

How to Lock Client "mobile number" in Profile Fields in WHMCS


Recommended Posts

thanks,i wrote this html code for hook, can i use html for hook?or i should write php?

 <div class="col-md-9 pull-md-right main-content">
    
   <form method="post" action="?action=details" role="form">

<div class="row">

        <div class="col-sm-6">

           <div class="form-group">
                        
                        <div class="control">
                        
                            <input type="text" name="customfield[51]" id="customfield51"  disabled="disabled" size="30" class="form-control"> 
                            
                        </div>
            </div> 
                            
            
        </div>
    </div>
    </form>
</div>

Any solution and answer would be great.
thanks

Link to comment
Share on other sites

3 hours ago, Victoria19 said:

thanks,i wrote this html code for hook, can i use html for hook?or i should write php?

it would need to be PHP because the HTML content for the customfields is stored in an array and therefore, you will have to manipulate the array.

an example hook to make a Client Custom Field readonly (or you could change to disabled if you wanted to), would be...

one problem with this solution is that although you can set a field to disabled/readonly, a knowledgable user can undo that setting in the browser and then change the content of that field.

if the fact the user could potentially modify the customfield readonly/disable status bothers you, then you'd probably need to use a second validation hook point to verify/prevent changes to that field.

this is why I didn't post this yesterday and thought it better for you to use the default phone number field... and it would be easier to do that now after only using WHMCS fora week or so than it would be if you had been using it for 10 years. 🙂

Link to comment
Share on other sites

thanks alot for a complete explanation.

but i have some problems

at first i wanted to use "Locked Client/User Profile Fields" in setting for locked client to edit mobile number but mobile number is a custom field

now i want to write a hook , for this i  have a question how can i understand   "ids in $ccfids " To add to the hook that you introduced.

i send the picture of our customer field 

Untitled.png

Link to comment
Share on other sites

7 hours ago, Victoria19 said:

now i want to write a hook , for this i  have a question how can i understand   "ids in $ccfids " To add to the hook that you introduced.

if you tell me that your mobile phone custom field ID is #51 (which is what your code suggests), then that makes that line in the hook become...

$ccfids = array(51);

that should make the mobile phone customfield disabled/readonly (whichever you set it to be).

Link to comment
Share on other sites

thank you ,but i have some problems

i used these codes but does not worked

<?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(51);
    
        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");
 
 
 
and i used that changes too but Had no effect
 

as you say, you could untick the "admin only" checkbox and then in clientareadetails.tpl, change...

 

 

            {if $customfields}
               {foreach from=$customfields key=num item=customfield}
                   <div class="form-group">
                       <label class="control-label" for="customfield{$customfield.id}">{$customfield.name}</label>
                       <div class="control">
                           {$customfield.input} {$customfield.description}
                       </div>
                   </div>
               {/foreach}
           {/if}
 

 

to...

 

            {if $customfields}
               {foreach from=$customfields key=num item=customfield}
                   <div class="form-group">
                       <label class="control-label" for="customfield{$customfield.id}">{$customfield.name}</label>
                       <div class="control">
                           {$customfield.value} {$customfield.description}
                       </div>
                   </div>
               {/foreach}
           {/if}
 

 

basically, you're just changing $customfield.input to $customfield.value - and that, as the code suggests, just displays the current content of the customfields and doesn't provide the user with an option to edit them.... though you may need to adjust the layout to suit the output

 
 
please help me 😞 
Edited by Victoria19
Link to comment
Share on other sites

8 hours ago, Victoria19 said:

and i used that changes too but Had no effect

if it doesn't work, then the ID you're using must be wrong - it can't be 51 and must be something else... it will make the field readonly or disabled only if the ID value used is correct.

BIUaZsG.png

you can change the output from a form field to just the values in a hook - though the principle that a user could change it's value would still exist.... you could even remove it from the array so that this field is no longer shown... however, to do anything to it, you need to find it's ID value....  inspecting the element in the browser and getting the number of the customfield should give you the correct value.

Link to comment
Share on other sites

hi, thanks. 

I right-clicked on the mobile number option and looked at the code with inspecting, which is as follows

<input type="text" name="customfield[51]" id="customfield51" value="" size="30" class="form-control">

Do we have to make another change in the code?

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