• Resolved hakuna4matata

    (@hakuna4matata)


    I have a form with some radio fields. Before the form is loaded, I would like to fill in my options on the fly. The options are different for every user and session and should not be saved as options in the form itself.

    I have found some solutions with filter:

    add_filter( 'forminator_field_single_markup', 'wpmudev_add_options', 10, 4 );

    But this “works” with HTML, and I would rather replace the options before they rendered. So I have tried with action like this:

    add_action( 'forminator_before_form_render', 'wpmudev_prefill_fields_form', 10, 5 );
    function wpmudev_prefill_fields_form( $id, $form_type, $post_id, $form_fields, $form_settings ) {
    if( $id == 762 ){
    foreach ($form_fields as &$field) {
    if ($field['element_id'] == 'radio-1') {
    $field['options'] = array(
    array(
    'label' => 'New Object 1',
    ....

    But this does not change the output of the field.

    Question: is there any possibility to provide the options for radio fields as array on the fly without messing HTML via str_replace in forminator_field_single_markup? Or is this the only option?

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Define radio options dynamically’ is closed to new replies.