{"id":697,"date":"2019-11-29T12:15:56","date_gmt":"2019-11-29T12:15:56","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2019\/11\/29\/create-input-tag-with-disabled-attribute-in-magento-2-system-xml\/"},"modified":"2025-05-22T15:18:50","modified_gmt":"2025-05-22T09:48:50","slug":"create-input-tag-with-disabled-attribute-in-magento-2-system-xml","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/create-input-tag-with-disabled-attribute-in-magento-2-system-xml\/","title":{"rendered":"How To Create Input Tag With Disabled Attribute In Magento 2 system.xml"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In the previous blog, I posted the solution to <a href=\"https:\/\/meetanshi.com\/blog\/create-input-tag-with-disabled-attribute-in-magento-2-system-xml\/\">create input tag with disabled attribute in Magento system.xml<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This solution is supposed to be implemented when you want to restrict the admin to change the values of particular fields for the proper working of your <a href=\"https:\/\/meetanshi.com\/magento-2-extensions.html\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 extensions<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Again, I&#8217;ve come up with a similar solution but for Magento 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Create input tag with disabled attribute in Magento 2 system.xml<\/strong> and restrict the admin users from changing the values of fields like passwords, <a title=\"Magento API Integration Service\" href=\"https:\/\/meetanshi.com\/magento-api-integration-service.html\" target=\"_blank\" rel=\"noopener\">API integration<\/a> key and its details, etc.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method To Create Input Tag With Disabled Attribute In Magento 2 system.xml:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Find if the field code in system.xml is as below:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;field id=\"token\" translate=\"label comment\" type=\"text\" sortOrder=\"20\" showInDefault=\"1\" showInWebsite=\"0\" showInStore=\"0\">\n      &lt;label>Auth Token&lt;\/label>\n&lt;\/field><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">and replace it with below code:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;field id=\"token\" translate=\"label comment\" type=\"text\" sortOrder=\"20\" showInDefault=\"1\" showInWebsite=\"0\" showInStore=\"0\">\n      &lt;label>Auth Token&lt;\/label>\n      &lt;frontend_model>Vendor\\Extension\\Block\\System\\Config\\Form\\Field\\Disable&lt;\/frontend_model>\n&lt;\/field><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create a new file <em><strong>Disable.php<\/strong><\/em> at <strong><strong>Vendor\\Extension\\Block\\System\\Config\\Form<\/strong><\/strong> &nbsp;folder<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nnamespace Vendor\\Extension\\Block\\System\\Config\\Form\\Field;\n\nuse Magento\\Framework\\Data\\Form\\Element\\AbstractElement;\nuse Magento\\Config\\Block\\System\\Config\\Form\\Field;\n\nclass Disable extends Field\n{    \n    protected function _getElementHtml(AbstractElement $element)\n    {\n        $element->setDisabled('disabled');\n        return $element->getElementHtml();\n\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That was all.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do not let any user play with your configuration! Give them access to only the selected fields. Disable the rest of them with the above solution.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do share the solution with fellow developers via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous blog, I posted the solution to create input tag with disabled attribute in Magento system.xml This solution is supposed to be implemented&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-697","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/697","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=697"}],"version-history":[{"count":5,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/697\/revisions"}],"predecessor-version":[{"id":15166,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/697\/revisions\/15166"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=697"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=697"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=697"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}