Home › Forums › Quform WordPress › Quform v2 Dynamic default value pre display check boxes
- This topic has 4 replies, 3 voices, and was last updated 6 years ago by Ally.
- AuthorPosts
- February 20, 2018 at 4:31 pm #24410TerrenceLPParticipant
Hello,
There is no Dynamic default value in QF2 documentation. Based on QF1 example –
echo iphorm(1, array(
‘my_parameter’ => ‘Banana’,
‘my_parameter2’ => ‘Apple’
));What has to be done to set a Dynamic Default Values for a Checkbox Group? I have the function and the option values ready to do in my pre-display – but how do i pre-populate this element?
February 20, 2018 at 8:27 pm #24416TerrenceLPParticipantTaken from here – Original Post that helped me
From the above post I was able to get what I needed. NOTE* I’m calling an external DB table.
add_action('quform_pre_display_3', function (Quform_Form $form) {
// Type form field ID = quform_3_7
global $wpdb;
$type_results = $wpdb->get_results( "SELECT id, name FROM master_media.type", OBJECT );
$type_results = json_decode(json_encode($type_results), true);
$type_results_array = array('0'=>'Default');
$select_type = $form->getElement('quform_3_7');
if ($select_type) {
foreach ($type_results as $type_value) {
$options_type[] = array('label' => $type_value['name'], 'value' => $type_value['id'], 'id' => $type_value['id']);
}
$select_type->setOptions($options_type);
}
});
Works like a charm and always pulls the latest options from the DB.February 23, 2018 at 12:33 pm #24440AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
April 10, 2018 at 4:05 pm #24942leredacParticipantBonjoiur
when your add doc for dynamique value please ?
Thank TerrenceApril 13, 2018 at 5:06 pm #24980AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
- AuthorPosts
- You must be logged in to reply to this topic.