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
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
-
see this magecomp.com/blog/…Waqar Ali– Waqar Ali2021年06月02日 07:16:22 +00:00Commented 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/fieldJay Parmar– Jay Parmar2021年06月02日 07:19:12 +00:00Commented Jun 2, 2021 at 7:19
-
yopu have to add regexWaqar Ali– Waqar Ali2021年06月02日 08:04:33 +00:00Commented Jun 2, 2021 at 8:04
1 Answer 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
Devidas
3,3731 gold badge30 silver badges68 bronze badges
Explore related questions
See similar questions with these tags.
default