It’s possible to set the available options of a Select Menu, Radio Buttons, Checkboxes or Multi Select element using a bit of PHP code.
Note: you should go to the element settings, on Data tab, and turn off the Validate submitted value option otherwise you will not be able to submit a dynamically added option.
Use WordPress pages as options
Add the following code to the theme functions.php file (or create a plugin for it).
123 4 5 6 7 8 9 10 11 12 13 14 | add_action('quform_pre_display_1', function (Quform_Form $form) { $element = $form->getElement('quform_1_3'); if ($element instanceof Quform_Element_Multi) { $options = array(); $posts = get_posts(array('numberposts' => -1, 'post_type' => 'page')); foreach ($posts as $post) { $options[] = array('label' => $post->post_title, 'value' => $post->post_title, 'id' => $post->ID); } $element->setOptions($options); } }); |
add_action('quform_pre_display_1', function (Quform_Form $form) { $element = $form->getElement('quform_1_3'); if ($element instanceof Quform_Element_Multi) { $options = array(); $posts = get_posts(array('numberposts' => -1, 'post_type' => 'page')); foreach ($posts as $post) { $options[] = array('label' => $post->post_title, 'value' => $post->post_title, 'id' => $post->ID); } $element->setOptions($options); } });
1 2 34 5 6 7 8 9 10 11 12 13 14 15 16 | function my_set_form_options(Quform_Form $form) { $element = $form->getElement('quform_1_3'); if ($element instanceof Quform_Element_Multi) { $options = array(); $posts = get_posts(array('numberposts' => -1, 'post_type' => 'page')); foreach ($posts as $post) { $options[] = array('label' => $post->post_title, 'value' => $post->post_title, 'id' => $post->ID); } $element->setOptions($options); } } add_action('quform_pre_display_1', 'my_set_form_options'); |
function my_set_form_options(Quform_Form $form) { $element = $form->getElement('quform_1_3'); if ($element instanceof Quform_Element_Multi) { $options = array(); $posts = get_posts(array('numberposts' => -1, 'post_type' => 'page')); foreach ($posts as $post) { $options[] = array('label' => $post->post_title, 'value' => $post->post_title, 'id' => $post->ID); } $element->setOptions($options); } } add_action('quform_pre_display_1', 'my_set_form_options');