• Hi

    How to auto-populate checkboxes and radio-buttons with dynamic values from DB?
    – As these values are dynamic (from the DB), so I cannot use default:1 etc. while declaring the control in the form.
    – It is possible to use default:shortcode_attr in the shortcode (along with functions.php changes), but that did not work.

    Please let me know how to do that!

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello @mplusplus,

    Please see this comment, it will help you for sure:
    Create radiobuttons with custom post type.

    Best regards,
    Yordan.

    Thread Starter mplusplus

    (@mplusplus)

    Hi @yordansoares

    Unfortunately, this does not work for my case.
    He is using [radio YOUR CF7 FIELDNAME HERE use_label_element default:1]. This will need me to declare the pre-selected value in the form, which I cannot (as I need to pull values from the database, so, my form values need to be declared on the page where the CF7 shortcode is).

    If you come across anything else please do let me know. Or if you can add this feature that will be great. It is very common for us to pre-populate a form with radio-buttons and checkboxes.

    Thanks so much for remembering this.

    Hello @mplusplus,

    Please check the code snippet again. You don’t need to declare any value, just use the same form tag name in your code snippet, and it will populate with the values from the database.

    The query use get_posts() to fetch post types, but you can change this if you want to use a taxonomy or other kind of data.

    Best regards,
    Yordan.

    Thread Starter mplusplus

    (@mplusplus)

    Hi @yordansoares

    Sure, I checked it again. I am not using any custom post type etc. I just use the CF7 fields and they are being saved in the database in a table.

    – Did you mean that instead of get_posts() I will write my own function to retrieve data from the DB table? I can do that.
    – The code is populating the fields from the database, however, I need to pre-populate the selection by the current user in those radio buttons and checkboxes. With the given example, they are auto-populating default:1, which will not work in my case (as this is user-dependent and I cannot hardcode this).

    Please let me know if I misunderstood you.

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to auto-populate checkboxes and radiobuttons with dynamic values from DB??’ is closed to new replies.