Jump to content

How to Lock Custom Created Fields?


zainyaqoob

Recommended Posts

Hi, I am using WHMCS, While users register account at our website their are form fields which become non-editable after registration, there is option in WHMCS admin panel which allow you to select which fields you wanted to make Non-Editable, But if we create some custom fields there is no option in whmcs to make that custom fields Non-Editable, that fields remain editable after registration, I need a way to prevent clients from editing custom fields the fields which I create new. I attahed the screen shot of WHMCS admin option for more to understand.

 

custom.png

Link to comment
Share on other sites

  • 2 months later...
  • 4 years later...

 in your template edit this file:

 clientareadetails.tpl

add this code:

<script type="text/javascript">
$(function() {
    $("#customfieldXX").attr("readonly", "readonly");
});</script>

Replace customfieldXX with your customfiled address like: customfield44

for prevent to Bypass the code add file whit this name:

PreventChangesToClientCustomFields.php 

in includes/hooks

<?php
use WHMCS\Database\Capsule;
add_hook('CustomFieldSave', 1, function($vars)
{
    $ReadOnlyFields = array('43', '63'); // IDs of Custom Fields that cannot be edited
    $DisallowAdmin = false; // true = Even Administrators are not allowed to edit | false = Administrators can freely update Custom Fields

    /* Do not edit below */
    $IsAdmin = (basename($_SERVER['PHP_SELF']) == 'clientsprofile.php' ? true : false);
    $IsNewClient = (in_array(basename($_SERVER['PHP_SELF']), array('register.php', 'cart.php')) ? true : false);

    if (in_array($vars['fieldid'], $ReadOnlyFields) AND (($IsAdmin AND $DisallowAdmin) OR (!$IsAdmin)) AND !$IsNewClient)
    {
        return array('value' => Capsule::table('tblcustomfieldsvalues')->where(['fieldid' => $vars['fieldid'], 'relid' => $vars['relid']])->first(['value'])->value);
    }
});

replcae array('43', '63') with your custon filed item like: $ReadOnlyFields = array('44')

Edited by ambaha
Link to comment
Share on other sites

  • 2 years later...

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