浏览文章
文章信息
Magento2 system field add validate|Magento2 system.xml添加验证|sytem.xml验证类型
14311
xyxtem.xml示例
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd"> <system> <tab id="webkul" translate="label" sortOrder="10"> <label>Webkul</label> </tab> <section id="test" translate="label" type="text" sortOrder="300" showInDefault="1" showInWebsite="1" showInStore="1"> <label>Test Configuration</label> <tab>webkul</tab> <resource>Webkul_Test::config_test</resource> <group id="settings" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1"> <field id="custom_email" translate="label comment" sortOrder="0" type="text" showInDefault="1" showInWebsite="0" showInStore="0"> <label>Enter Email Id</label> <validate>validate-email</validate> </field> </group> </section> </system> </config>后台示例
编写的xml
<validate>required-entry validate-email</validate>所有验证类型
'validate-no-html-tags' => 'HTML tags are not allowed' 'validate-select' => 'Please select an option.' 'required-entry' => 'This is a required field.' 'validate-number' => 'Please enter a valid number in this field.' 'validate-digits' => 'Please use numbers only in this field. Please avoid spaces or other characters such as dots or commas.' 'validate-date' => 'Please enter a valid date.' 'validate-email' => 'Please enter a valid email address. For example johndoe@domain.com.' 'validate-url' => 'Please enter a valid URL. Protocol is required (http://, https:// or ftp://)' 'validate-not-negative-number' => 'Please enter a number 0 or greater in this field.' 'validate-zero-or-greater' => 'Please enter a number 0 or greater in this field.' 'validate-state' => 'Please select State/Province.' 'validate-cc-number' => 'Please enter a valid credit card number.' 'validate-data' => 'Please use only letters (a-z or A-Z), numbers (0-9) or underscore(_) in this field, first character should be a letter.'