Home  >  Article  >  CMS Tutorial  >  How to customize forms in phpcms

How to customize forms in phpcms

angryTom
angryTomOriginal
2020-02-19 13:53:283902browse

How to customize forms in phpcms

How to customize the form in phpcms

The steps to customize the form are as follows:

(1 ): Open the backend, click on the module, find the form wizard, click on the add form wizard, and the following interface will appear.

How to customize forms in phpcms

(2): Next, we need to introduce the two options of template selection in the above figure and the template used by js calling. For template selection, it is actually On the front page of our form, the template used by js calls represents the jump operation performed after submitting the form. Under normal circumstances, we only need to switch the template and select part of the content to modify the form style. The template used by js calls does not require us to do so. For any operation, where is the template show_js.html used for the specific template selection show.html and js call stored?

The answer is under the phpcms\templates\default\formguide path. In practice, we only need to switch the template selection. Here I define a show_message.html file myself and switch the template selection location to My show_message.html file.

Related recommendations: phpcms tutorial

(3): Next is the writing process of my show_message.html file. The writing of this file needs to refer to the original show.html As for writing, let’s take a look at how the form part of show.html is written.

<form method="post" action="?m=formguide&c=index&a=show&formid={$formid}&siteid=<?php echo $this->siteid;?>" name="myform" id="myform">
   <table class="table_form" width="100%" cellspacing="0">
   <tbody>
   {loop $forminfos_data $field $info}
    {if $info[&#39;formtype&#39;]==&#39;omnipotent&#39;}
        {loop $forminfos_data $_fm $_fm_value}
            {if $_fm_value[&#39;iscomnipotent&#39;]}
                {php $info[&#39;form&#39;] = str_replace(&#39;{&#39;.$_fm.&#39;}&#39;,$_fm_value[&#39;form&#39;],$info[&#39;form&#39;]);}
            {/if}
        {/loop}
    {/if}
    <tr>
      <th width="80">{if $info[&#39;star&#39;]} <font color="red">*</font>{/if} {$info[&#39;name&#39;]}
      </th>
      <td>{$info[&#39;form&#39;]}  {$info[&#39;tips&#39;]}</td>
    </tr>
    {/loop}
    </tbody>
    </table>
    <input type="submit" name="dosubmit" id="dosubmit" value=" 提交 "> <input type="reset" value=" 取消 ">
</form>

The more important parts here are the following parts

(1): The action part of the form, the value of this part is

? m=formguide&c=index&a=show&formid={$formid}&siteid=siteid;?>, usually you can copy it directly to the action part of your form.

(2): As for the name=”myform” id=”myform” part under the form tag, it is optional. You can write it if you want to but you can also remove it if you don’t want to.

(3): Next is the {loop $forminfos_data $field $info} loop body. This loop body is more important. What $field gets is when you add fields after creating the form wizard. The English name of the field corresponds to the field in the database that stores your message information, and $info stores some additional information about the data table fields you define, such as the Chinese names of the data table fields. Where are these values ​​set? ? It is the content filled in in the interface that appears after you create the form and click Add Field. Specifically, it is the following interface:

How to customize forms in phpcms

(4): Next is the variable traversal loop part, the main function of this part is to loop through the form information content created for us based on the data table system we created, such as

{$info['form']} {$info['tips']}< ;/td>The content obtained by {$info['form']} in this code is the form style created by the system for us by default corresponding to the current field. For example, as shown below, the value in the picture below is what I directly The result value obtained by printing $info:

How to customize forms in phpcms

(5): The last thing to note is

So far, we have checked the default show.html form style implementation of the phpcms system. Next, we implement our own form style. I will directly post my implementation code

<form method=&#39;post&#39; class="met-form met-form-validation" enctype="multipart/form-data" action=&#39;{APP_PATH}index.php?m=formguide&c=index&a=show&formid={$formid}&action=js&siteid=<?php echo $this->siteid;?>&#39;>
     {loop $forminfos_data $field $info}
     {php var_dump($info)}
     {if $info[&#39;formtype&#39;]==&#39;text&#39;}
     <div class=&#39;form-group&#39;>
        <input name=&#39;info[{$field}]&#39; class=&#39;form-control&#39; type=&#39;text&#39; placeholder=&#39;{$info[tips]}&#39; />
     </div>
     {/if}
     {if $info[&#39;formtype&#39;]==&#39;textarea&#39;}
     <div class=&#39;form-group&#39;>
        <textarea name=&#39;info[{$field}]&#39; class=&#39;form-control&#39;  placeholder=&#39;{$info[tips]} &#39; rows=&#39;10&#39;></textarea>
     </div>
     {/if}
     {/loop}
     <div class="form-group m-b-0">
     <button type="submit" name="dosubmit" id="dosubmit" class="btn btn-primary btn-lg btn-block btn-squared" value=" 提交 ">提交留言</button>
     </div>
</form>

I The biggest changes to the original show.html in this code are the following points

First of all, my own form style is class="met-form met-form-validation", and this part does not exist in the original code Content

I removed the content value of name="myform" id="myform"

Next, create the input part of the form and also use

{loop $ forminfos_data $field $info}, and use $info['formtype'] to determine whether it is a single line of text or a multi-line text

Take a single line of text as an example

, in this part name='info[{$field}]' comparison The key is, if you don’t write these few lines of code in your form, you will find that after submitting the form, the content information you filled in will not be in the database at all, and the message content you wrote will not appear in the message information list in the background

Finally, the code name="dosubmit" is added to the submit part. Note that without this code, you will still not be able to find your message content in the database.

So far, we can create our own style form!

For more phpcmswebsite construction video tutorial, please pay attention to the PHP Chinese website!

The above is the detailed content of How to customize forms in phpcms. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is phpcms typeidNext article:What is phpcms typeid