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>
3
  • see this magecomp.com/blog/…
    – Waqar Ali
    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
    – Joy Poly
    Jun 2, 2021 at 7:19
  • yopu have to add regex
    – Waqar Ali
    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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.