
How to modify the required fields in dedecms custom form options?
The example in this article describes the solution to the required modification of custom form options in dedecms. Share it with everyone for your reference. The specific method is as follows:
Recommended learning: 梦Weavercms
Method 1: First, we need to use a piece of php code to determine the required verification options.
1. Let’s first add the following code under line 40 in the plus/diy.php file:
The code is as follows:
//增加必填字段判断
if($required!=''){
if(preg_match('/,/', $required))
{
$requireds = explode(',',$required);
foreach($requireds as $field){
if($$field==''){
showMsg('带*号的为必填内容,请正确填写', '-1');
exit(); //phpfensi.com
}
}
}else{
if($required==''){
showMsg('带*号的为必填内容,请正确填写', '-1');
exit();
}
}
}
//end2. After saving, find this on the form page Line of code.
The code is as follows:
<form action="/plus/diy.php" enctype="multipart/form-data" method="post" style="padding: 0px; margin: 0px; " >`````
Under this line of code, add the code:
The code is as follows:
<input type="hidden" name="required" value="content,name,tel" />````
Method 2: I finally It is implemented in another way, add a JQ and a JS to your form page:
The code is as follows:
<script src="js/jquery-1.8.0.js"></p> <p><script src='{dede:global.cfg_templets_skin/}/style/js/js.js' type="text/javascript">The content of this js is:
The code is as follows :
<!--
$(document).ready(function()
{
//验证
$('#complain').submit(function ()
{
if($('#yname').val()==""){
$('#yname').focus();
alert("姓名不能为空!");
return false;
}
if($('#qq').val()=="")
{
$('#qq').focus();
alert("手机号码不能为空!");
return false;
}
if($('#tel').val()=="")
{
$('#tel').focus();
alert("所选产品不能为空!");
return false;
}
if($('#dizhi').val()=="")
{
$('#dizhi').focus();
alert("地址不能为空!");
return false;
}
})
});
-->
<input type='text' name='ytel' id='ytel' style='width:250px' class='intxt' value='' />*Note: The part is the ID of your form (if not, please add it in the form) and the required ID.
The above is the detailed content of How to modify the required fields of custom form options in dedecms. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software





