Insert custom additional attributes to an input field

[ad_1]

Hello @rierajf

Thank you very much for using our plugin. Yes, that’s possible, but it requires to use the plugin events.

I’ll try to describe the process with a hypothetical example.

Assuming you have the checkbox field:

<label>Posts</label>
[checkbox posts use_label_element]

And you want to populate it with the list of website posts, using the post ID as checkbox values and post_title as their texts, and additionally, you want to fill their data-prix attributes with the posts authors’ ids.

Enter the following form structure:

<label>Posts</label>
[checkbox posts use_label_element]

[cf7-recordset id="post-db" type="database" query="SELECT ID, post_author, post_title FROM {wpdb.posts}"]
[cf7-link-field recordset="post-db" field="posts" value="ID" text="post_title"]

<script>
jQuery(document).on('change', '[name="posts[]"]', function(evt, attr){
    if(attr == 'cf7-ds-fill') {
        let list = cf7_datasource_get_recordset_data('post-db');
        for(let i in list) {
            jQuery('[name="posts[]"]:eq('+i+')').attr('data-prix', list[i]['post_author']);
        }
    }
});
</script>

The event is triggered after filling in the checkbox choices. It walks through the recordset records and assigns the data-prix attribute to the checkboxes with post_author information.

Best regards.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer