0

I want to set custom validation on system config file that "accept character do not allow any script tag" only accept like that

ex. config/group/field, config/group/field

enter image description here

Here is my system.xml file

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
 <system>
 <tab id="ccc" translate="label" sortOrder="10">
 <label>Ccc</label>
 </tab>
 <section id="secureconfig" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
 <class>separator-top</class>
 <label>SecureConfig</label>
 <tab>ccc</tab>
 <resource>Ccc_SecureConfig::secure_config</resource>
 <group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
 <label>General Configuration</label>
 <field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
 <label>Module Enable</label>
 <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
 </field>
 <field id="config_path" translate="label" type="textarea" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
 <label>Config Path </label>
 <comment>Add Config Path with , seprator Like (config/group/field, config/group/field)</comment>
 <validate>required-entry validate-data</validate>
 </field>
 </group>
 </section>
 </system>
</config>
Vibhore Jain
7071 gold badge7 silver badges16 bronze badges
asked Jun 2, 2021 at 7:14
3
  • see this magecomp.com/blog/… Commented Jun 2, 2021 at 7:16
  • that only for lenght , i need validation as = accept character do not allow any script tag , like config/group/field, config/group/field Commented Jun 2, 2021 at 7:19
  • yopu have to add regex Commented Jun 2, 2021 at 8:04

1 Answer 1

1

try below code

<field id="config_path" translate="label" type="textarea" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
 <label>Config Path </label>
 <comment>Add Config Path with , seprator Like (config/group/field, config/group/field)</comment>
 <frontend_class>validate-alpha</frontend_class>
</field>

for validation, you need to add like this

<frontend_class>validate-alpha</frontend_class>

validate-alpha -- > Character only

validate-number -- > Number Only

required-entry --> required field

answered Jun 2, 2021 at 12:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.