首页 WordPress函数大全 acf_register_form()

acf_register_form()

2020-06-28 / 1897阅 / 悠然

如何你看完本文还不知道如何使用该函数,可以联系我定制视频教程,50元/个函数,学不会全额退款

本视频需要登录以后才能播放

登录

描述

注册与acf_form()函数一起使用的表单。有许多可用于自定义表单的设置,这些设置是通过添加到$settings数组来设置的(请参见下文)。

参量

<?php acf_register_form( $settings ); ?> 

$设置

(字符串|数组)注册表单的设置或“ id”的数组。

  • id
    (字符串)表单的唯一标识符。默认为'acf-form'。'id' => 'acf-form',
  • post_id
    (整数|字符串)用于确定要显示的字段,加载数据的位置和保存数据的位置的发布ID。默认为当前帖子ID。也可以发送到“ new_post”以在提交时创建新帖子。'post_id' => false,
  • new_post
    (数组)当上述属性设置为“ new_post”时,此设置用于创建帖子。有关可用参数,请参见wp_insert_post'new_post' => false,
  • field_groups
    (Array)字段组ID /键的数组,以覆盖此表单中显示的字段。'field_groups' => false,
  • 字段
    (数组)字段ID /键的数组,用于覆盖此表单中显示的字段。'fields' => false,
  • post_title
    (布尔值)是否显示帖子标题文本字段。默认为false。'post_title' => false,
  • post_content
    (布尔值)是否显示帖子内容编辑器字段。默认为false。'post_content' => false,
  • form
    (布尔值)是否创建form元素。添加到现有表单时很有用。默认为true。'form' => true,
  • form_attributes
    (Array)表单元素的数组或HTML属性。'form_attributes' => array(),
  • return
    (String)提交表单后要重定向到的URL。默认为带有GET参数'?updated = true'的当前URL。
    特殊的占位符'%post_url%'将转换为帖子的永久链接。
    特殊的占位符'%post_id%'将转换为帖子的ID。'return' => '',
  • html_before_fields
    (String)在字段之前添加的额外HTML。'html_before_fields' => '',
  • html_after_fields
    (String)在字段之后添加的额外HTML。'html_after_fields' => '',
  • Submit_value
    (字符串)显示在提交按钮上的文本。'submit_value' => __("Update", 'acf'),
  • Updated_message
    (字符串)重定向后在窗体上方显示的消息。也可以设置为false,不发送任何消息。'updated_message' => __("Post updated", 'acf'),
  • label_placement
    (字符串)确定字段标签相对于字段的位置。默认为“ top”。选择“顶部”(上方字段)或“左侧”(旁边字段)。'label_placement' => 'top',
  • struction_placement
    (字符串)确定相对于字段放置字段指令的位置。默认为“标签”。选择“标签”(在标签下方)或“字段”(在字段下方)。'instruction_placement' => 'label',
  • field_el
    (String)确定用于包装字段的元素。默认为'div'。可以选择“ div”,“ tr”,“ td”,“ ul”,“ ol”,“ dl”。'field_el' => 'div',
  • uploader
    (字符串)是使用WP上传器还是用于图像和文件字段的基本输入。默认为'wp'。“ wp”或“ basic”的选择。'uploader' => 'wp',
  • honeypot
    (布尔值)是否包括隐藏的输入字段以捕获非人为形式的提交。默认为true。'honeypot' => true,
  • html_updated_message
    (字符串)用于呈现更新的消息的HTML。'html_updated_message' => '<div id="message" class="updated"><p>%s</p></div>',
  • html_submit_button
    (字符串)用于呈现提交按钮的HTML。'html_submit_button' => '<input type="submit" class="acf-button button button-primary button-large" value="%s" />',
  • html_submit_spinner
    (字符串)用于呈现提交按钮加载微调器的HTML。'html_submit_spinner' => '<span class="acf-spinner"></span>',
  • kses
    (布尔值)是否$_POST使用wp_kses_post()函数清除所有数据。默认为true。'kses' => true

变更日志

  • kses 在版本5.6.5中添加。
  • uploader 在版本5.2.4中添加。
  • honeypot 在版本5.3.4中添加
  • html_updated_message,,html_submit_buttonhtml_submit_spinner在5.5.10版中添加

例子

基本用法

本示例演示如何在functions.php文件中注册表单,然后在页面模板中显示该表单。

functions.php

add_action('acf/init', 'my_acf_form_init');
function my_acf_form_init() {

    // Check function exists.
    if( function_exists('acf_register_form') ) {

        // Register form.
        acf_register_form(array(
            'id'       => 'new-event',
            'post_id'  => 'new_post',
            'new_post' => array(
                'post_type'   => 'event',
                'post_status' => 'publish'
            ),
            'post_title'  => true,
            'post_content'=> true,
        ));
    }
} 

page-new-event.php

<?php acf_form_head(); ?>
<?php get_header(); ?>

<div id="primary" class="content-area">
    <div id="content">
        <?php acf_form('new-event'); ?>
    </div><!-- #content -->
</div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?> 
大家谈论
    我的见解