PHP a custom form implementation without adding fields _php tutorial

Source: Internet
Author: User
Many open-source program systems have custom form features, such as Weaving dreams and empires; Their custom forms create a new table, which is an implementation, but sometimes we may need some ancillary content, or we don't need to build multiple tables, we just want to use a field to store what we have attached, At this point we can achieve this by the following way.

Let's take a look at the implementation effect:

We can set his hint text, field, type, default value, parameter, sort, whether the list is displayed. Of course, we can also add some of the similar presentation, whether highlighting and so on. There are types of text, drop-down, single-selection, check, multiline text, and so on. Look at the table structure:

ID Needless to say, name is the form hint text, that is, such as name, gender, etc., Qian and Ziduan are combined, in order to be good, with a prefix and fields to form a custom field label, easier to distinguish, type is the kind, value is the default value, Whcs is the parameter, which is the default when the type is text or multiple lines of text is in effect, the first parameter limits the maximum number of bytes, and the second limits the length of a text. Role is sort, and Yesno is displayed in the foreground.

The code does not need to elaborate, in the setting of this custom form is relatively simple, is to traverse, according to its type combination.

Let me show you the code for this place.

[PHP] View plaincopyprint? Get parameter configuration information
$system = $this->tmp_mod->getallsystem ();
if ($system) {
foreach ($system as $key = = $val) {
if ($val [' name ']&& $val [' Ziduan ']) {
$zhu = ";
if ($val [' value ']) {
$value = @explode (', ', $val [' value ']);
}
if ($val [' Whcs ']) {
$whcs = @explode (' $ ', $val [' Whcs ']);
}
if (2== $val [' type ']) {
$zhu = ''; foreach ($value as $k = = $v) {$zhu. = ''. $v. '; } $zhu. = '';
}elseif (3== $val [' type ']) {
foreach ($value as $k = = $v) {
$check = ";
if (' 0 ' = = $k) {
$check = ' checked ';
}
$zhu. = ''. $v;
}
}elseif (4== $val [' type ']) {

foreach ($value as $m = = $n) {
$zhu. = ''. $n;
}
}

$biao [$key] [' name '] = $val [' name '];
Switch ($val [' type ']) {
Case ' 1 ': $biao [$key] [' Value ']= '
Maxlength= "'. $whcs [0]. ' style= ' width: '. $whcs [1]. ' PX "value=". $val [' value ']. '/> ';
Case ' 2 ': $biao [$key] [' Value ']= $zhu;
Case ' 3 ': $biao [$key] [' Value ']= $zhu;
Case ' 4 ': $biao [$key] [' Value ']= $zhu;
Case 5: $biao [$key] [' Value ']= '<textarea id="'.$val['qian'].$val['ziduan'].'" style="width:'.$whcs[0].'px;height:'.$whcs[1].'px" name="'.$val['qian'].$val['ziduan'].'">'. $val [' value ']. '</textarea>'; break;
Default:;
}
}
}
}

http://www.bkjia.com/PHPjc/477940.html www.bkjia.com true http://www.bkjia.com/PHPjc/477940.html techarticle many open-source program systems have custom form features, such as Weaving dreams and empires; Their custom forms create a new table, which is a way to do it, but sometimes I ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.