[Phpcms V9 two-time development] custom field model-Add field type

Source: Internet
Author: User

Steps/Methods
  1. Open the Phpcms\modules\content\fields directory, copy the folder Downfiles, and rename it to Textgroups.

  2. Open the phpcms\modules\content\fields\fields.inc.php file to increase the field type:

    ' textgroups ' + ' multiple file uploads ',

  3. Open the Phpcms\modules\content\fields\textgroups directory (the first copy of the folder) and modify the following files:

  4. form.inc.php

    Function textgroups ($field, $value, $fieldinfo) {
    Extract (String2array ($fieldinfo [' setting ']));
    $list _str = ";
    if ($value) {
    $value = String2array (Html_entity_decode ($value, ent_quotes));
    if (Is_array ($value)) {
    foreach ($value as $_k=>$_v) {
    $list _str. = "<div id= ' Textsgroups{$_k} ' > < Input type= ' text ' name= ' {$field}_fx[] ' value= ' {$_v[fx]} ' style= ' width:100px; ' class= ' Input-text ' > <input type= ' Text ' name= ' {$field}_fj[] ' value= ' {$_V[FJ]} ' style= ' width:100px; ' class= ' Input-text ' > <input type= ' text ' name= ' {$field}_cx[] ' value= ' {$_v[cx]} ' style= ' width:100px; ' class= ' Input-text ' > <input type= ' text ' name= ' {$field}_KD [] ' value= ' {$_V[KD]} ' style= ' width:100px; ' class= ' Input-text ' > <input type= ' text ' name= ' {$field}_vip[] ' value= ' {$_V[VIP]} ' style= ' width:100px; ' class= ' Input-text ' > <a href=\ ' javascript:remove_div (' textsgroups{$_k} ') \ " > ". L (' Remove_out '). " </a></div> ";
    }
    }
    }

    $string = ' <script type=text/javascript>
    function Add_textsfile (Returnid) {
    var ids = parseint (Math.random () * 10000);
    var str = "<li id=\ ' textsgroups" +ids+ "\ ' > <input type=\ ' text\ ' name=\ '" +returnid+ "_fx[]\ ' value=\ ' \ ' style=\ ' Width:100px;\ ' class=\ ' input-text\ ' > <input type=\ ' text\ ' name=\ ' "+returnid+" _fj[]\ ' value=\ ' \ ' style=\ ' width : 100px;\ ' class=\ ' input-text\ ' > <input type=\ ' text\ ' name=\ ' "+returnid+" _cx[]\ ' value=\ ' \ ' style=\ ' width:100px ; \ ' class=\ ' input-text\ ' > <input type=\ ' text\ ' name=\ ' "+returnid+" _kd[]\ ' value=\ ' \ ' style=\ ' width:100px;\ ' Class=\ ' input-text\ ' > <input type=\ ' text\ ' name=\ ' "+returnid+" _vip[]\ ' value=\ ' \ ' style=\ ' width:100px;\ ' class =\ ' input-text\ ' > <a href=\ "javascript:remove_div (\ ' textsgroups ' +ids+" \ ') \ ">Remove</a> </li>" ;
    $ (\ ' #\ ' +returnid). append (str);
    }</script> ';
    $string. = ' <input name= ' info[' $field. ' "type=" hidden "value=" 1 ">
    <fieldset class= "Blue pad-10" >
    <legend> '. L (' mm_fxlist '). ' </legend><div id= "tt" >
    <input type= "text" value= "'. L (' Mm_fx '). ' "ReadOnly style=" width:100px;border:0; class= "Input-text" >
    <input type= "text" value= "'. L (' mm_fj '). ' "ReadOnly style=" width:100px;border:0; class= "Input-text" >
    <input type= "text" value= "'. L (' mm_cx '). ' "ReadOnly style=" width:100px;border:0; class= "Input-text" >
    <input type= "text" value= "'. L (' MM_KD '). ' "ReadOnly style=" width:100px;border:0; class= "Input-text" >
    <input type= "text" value= "'. L (' Mm_lyj '). ' "ReadOnly style=" width:100px;border:0; class= "Input-text" >
    </div> ';
    $string. = $list _str;
    $string. = ' <ul id= ' $field. ' "class=" Piclist "></ul>
    </fieldset>
    <div class= "Bk10" ></div>
    ‘;
    $string. = $str. " <input type=\ "button\" class=\ "button\" value=\ "". L (' mm_addfx '). " \ "Onclick=\" Add_textsfile (' {$field} ') \ ">";
    return $string;
    }

  5. Modify input.inc.php

    function textgroups ($field, $value) {
    $hotel = $_post[$field. ' _fx '];
    $hotel _FJ = $_post[$field. ' _FJ '];
    $hotel _cx = $_post[$field. ' _cx '];
    $hotel _KD = $_post[$field. ' _KD '];
    $hotel _VIP = $_post[$field. ' _vip '];
    $array = $temp = Array ();
    if (!empty ($hotel)) {
    foreach ($hotel as $key = = $hote) {
    $temp [' fx '] = $hote;
    $temp [' fj '] = $hotel _fj[$key];
    $temp [' cx '] = $hotel _cx[$key];
    $temp [' kd '] = $hotel _kd[$key];
    $temp [' vip '] = $hotel _vip[$key];
    $array [$key] = $temp;
    }
    }
    $array = array2string ($array);
    return $array;
    }

  6. Modified output.inc.php

    function textgroups ($field, $value) {

    Return String2array ($value);

    }

  7. Updates the background cache. Create a new field in the model, you can see the text group, and you can add it once created.

  8. Foreground call:<table>
    <tr><th> Room type </th><th> rate </th><th> bed type </th><th> Road Tour price </TH></TR >
    {Loop $fxinfo $v} <!--$fxinfo field name--
    <tr><td>{$v [fx]}</td><td>¥{$v [FJ]} meta </td><td>{$v [cx]}</td><td> <strong style= "color: #f60; font-size:18px;font-family:tahoma,helvetica,arial,sans-serif;" >¥{$v [vip]}</strong> Yuan </td></tr>
    {/loop}
    </table>

Precautions
    • Note that modifying the name of a function in several files is easy to ignore.

    • Note the closing and JS code of the quotation marks in the file contents.

      • Excerpt from: http://blog.csdn.net/shunzi110/article/details/8269571

[Phpcms V9 two-time development] custom field model-Add field type

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.