douchuifk90315 2019-02-01 10:16
浏览 52

获取用户元目的唯一ID布局灵活内容

I have a form that save the data in the usermeta and I'm using the flexible content to allow specific user to create forms depends of the country they are.

I'm trying to save it but I don't have a key/ID to save the question with the answer to allow to the future people can edit them because if I change the order of the same kind of sub field they just change the position in the array and that wont let me get an specific ID to save it in the user meta.

I'm just trying to make a dynamic form to the people are registering and in the future allow them to change it.

I tried using the key of the layout but the problem is that the layout can be ordered and that change the array where the key is save and doesn't let me relate in the future.

This is how I did it, I create the labels for the user and inputs

<?php
                    $mypost = get_page_by_title($user_country , OBJECT, 'Countries');

                    // check if the flexible content field has rows of data
                    if( have_rows('application_form_fields', $mypost->ID) ): ?>
                        <div class="col-sm-12">
                            <h2><?php _e('Extra Information', 'Adecco_Login_Plugin'); ?></h2>
                        </div>
                         <?php    // loop through the rows of data
                        $flex = get_field('application_form_fields');
                        error_log(print_r($mypost, true));
                         while ( have_rows('application_form_fields', $mypost->ID) ) : $row = the_row();

                             if( get_row_layout() == 'short_text' ):?>
                                 <div class="col-sm-12">
                                     <div class="form-row">
                                         <input type="text" name="uni" class="form-control" id="uni" placeholder="<?php the_sub_field('label'); ?>" required>
                                     </div>
                                 </div>

                             <?php elseif( get_row_layout() == 'long_text' ): ?>
                                 <div class="col-sm-12">
                                     <div class="form-row">
                                         <input type="text" name="uni" class="form-control" id="uni" placeholder="<?php the_sub_field('label'); ?>" required>
                                     </div>
                                 </div>

                             <?php elseif( get_row_layout() == 'multipick' ): ?>
                                 <div class="col-sm-12">
                                     <div class="form-row">
                                         <select id="field" name="field" class="form-control"  required>
                                             <option value=""><?php the_sub_field('label'); ?></option>
                                             <?php
                                             while ( have_rows('values') ) : the_row(); ?>
                                                 <option><?php the_sub_field('item_text') ?></option>
                                             <?php endwhile;
                                             ?>
                                         </select>
                                     </div>
                                 </div>
                             <?php elseif( get_row_layout() == 'checkbox' ): ?>
                                <div class="col-sm-12">
                                    <div class="form-row">
                                        <div class="col-sm-9">
                                            <label for="toggle3"><?php the_sub_field('label'); ?></label>
                                        </div>
                                        <div class="col-md-3">
                                            <input id="toggle-off3" name="toggle3" type="radio" value="No">
                                            <label class="radio" for="toggle-off3"><?php _e('No', 'Adecco_Login_Plugin'); ?></label>
                                            <input id="toggle-on3" name="toggle3" type="radio" value="Yes">
                                            <label class="radio" for="toggle-on3"><?php _e('Yes', 'Adecco_Login_Plugin'); ?></label>
                                        </div>
                                    </div>
                                </div>
                            <?php endif;

                            endwhile;

                    else :

                        // no layouts found
                        echo "No layout found";

                    endif;
[
    {
        "key": "group_5c509fc032e05",
        "title": "Application Form",
        "fields": [
            {
                "key": "field_5c509fd900af1",
                "label": "Custom Fields for Application Form",
                "name": "application_form_fields",
                "type": "flexible_content",
                "instructions": "",
                "required": 0,
                "conditional_logic": 0,
                "wrapper": {
                    "width": "",
                    "class": "",
                    "id": ""
                },
                "layouts": {
                    "5c509fe7de1c8": {
                        "key": "5c509fe7de1c8",
                        "name": "short_text",
                        "label": "Short Text",
                        "display": "table",
                        "sub_fields": [
                            {
                                "key": "field_5c50aab34181a",
                                "label": "Label",
                                "name": "label",
                                "type": "text",
                                "instructions": "",
                                "required": 1,
                                "conditional_logic": 0,
                                "wrapper": {
                                    "width": "",
                                    "class": "",
                                    "id": ""
                                },
                                "default_value": "",
                                "placeholder": "",
                                "prepend": "",
                                "append": "",
                                "maxlength": ""
                            }
                        ],
                        "min": "",
                        "max": ""
                    },
                    "5c50a5975061b": {
                        "key": "5c50a5975061b",
                        "name": "long_text",
                        "label": "Long Text",
                        "display": "table",
                        "sub_fields": [
                            {
                                "key": "field_5c50abad60442",
                                "label": "Label",
                                "name": "label",
                                "type": "text",
                                "instructions": "",
                                "required": 1,
                                "conditional_logic": 0,
                                "wrapper": {
                                    "width": "",
                                    "class": "",
                                    "id": ""
                                },
                                "default_value": "",
                                "placeholder": "",
                                "prepend": "",
                                "append": "",
                                "maxlength": ""
                            }
                        ],
                        "min": "",
                        "max": ""
                    },
                    "5c50a5d85061d": {
                        "key": "5c50a5d85061d",
                        "name": "multipick",
                        "label": "Multipick",
                        "display": "table",
                        "sub_fields": [
                            {
                                "key": "field_5c50abc760443",
                                "label": "Label",
                                "name": "label",
                                "type": "text",
                                "instructions": "",
                                "required": 1,
                                "conditional_logic": 0,
                                "wrapper": {
                                    "width": "",
                                    "class": "",
                                    "id": ""
                                },
                                "default_value": "",
                                "placeholder": "",
                                "prepend": "",
                                "append": "",
                                "maxlength": ""
                            },
                            {
                                "key": "field_5c50abd060444",
                                "label": "Values",
                                "name": "values",
                                "type": "repeater",
                                "instructions": "",
                                "required": 1,
                                "conditional_logic": 0,
                                "wrapper": {
                                    "width": "",
                                    "class": "",
                                    "id": ""
                                },
                                "collapsed": "",
                                "min": 0,
                                "max": 0,
                                "layout": "row",
                                "button_label": "Add Item",
                                "sub_fields": [
                                    {
                                        "key": "field_5c50abdc60445",
                                        "label": "Item Text",
                                        "name": "item_text",
                                        "type": "text",
                                        "instructions": "",
                                        "required": 1,
                                        "conditional_logic": 0,
                                        "wrapper": {
                                            "width": "",
                                            "class": "",
                                            "id": ""
                                        },
                                        "default_value": "",
                                        "placeholder": "",
                                        "prepend": "",
                                        "append": "",
                                        "maxlength": ""
                                    }
                                ]
                            }
                        ],
                        "min": "",
                        "max": ""
                    },
                    "layout_5c50ac6f6044a": {
                        "key": "layout_5c50ac6f6044a",
                        "name": "checkbox",
                        "label": "Checkbox (YES\/NO)",
                        "display": "table",
                        "sub_fields": [
                            {
                                "key": "field_5c50ac6f6044b",
                                "label": "Label",
                                "name": "label",
                                "type": "text",
                                "instructions": "",
                                "required": 1,
                                "conditional_logic": 0,
                                "wrapper": {
                                    "width": "",
                                    "class": "",
                                    "id": ""
                                },
                                "default_value": "",
                                "placeholder": "",
                                "prepend": "",
                                "append": "",
                                "maxlength": ""
                            }
                        ],
                        "min": "",
                        "max": ""
                    }
                },
                "button_label": "Add Field",
                "min": "",
                "max": ""
            }
        ],
        "location": [
            [
                {
                    "param": "post_type",
                    "operator": "==",
                    "value": "countries"
                }
            ]
        ],
        "menu_order": 0,
        "position": "normal",
        "style": "default",
        "label_placement": "top",
        "instruction_placement": "label",
        "hide_on_screen": "",
        "active": 1,
        "description": ""
    }
]
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP