Hi @alwanma27,
Forminator does not have such an option out of the box. The following workaround can help with populating the select field dynamically. Please check if that helps.
add_filter( 'forminator_cform_render_fields', function( $wrappers, $model_id ) {
if( $model_id != 361 ){
return $wrappers;
}
$select_fields_data = array(
'select-1' => 'users',
);
foreach ( $wrappers as $wrapper_key => $wrapper ) {
if ( ! isset( $wrapper[ 'fields' ] ) ) {
continue;
}
if ( isset( $select_fields_data[ $wrapper[ 'fields' ][ 0 ][ 'element_id' ] ] ) && ! empty( $select_fields_data[ $wrapper[ 'fields' ][ 0 ][ 'element_id' ] ] ) ) {
$users = get_users();
if ( ! empty( $users ) ) {
$new_options = array();
foreach( $users as $u ) {
$new_options[] = array(
'label' => $u->user_login,
'value' => $u->user_login,
'limit' => '',
'key' => forminator_unique_key(),
);
}
$wrappers[ $wrapper_key ][ 'fields' ][ 0 ][ 'options' ] = $new_options;
}
}
}
return $wrappers;
},10,2);
add_filter( 'forminator_replace_form_data', function( $content, $data, $original_content ) {
if( $data['form_id'] != 361 ){
return $content;
}
if ( ! empty( $content ) ) {
return $content;
}
$form_fields = Forminator_API::get_form_fields( $data['form_id'] );
$data_field = '';
foreach($data as $key => $value){
if ( strpos( $key, 'select' ) !== false ) {
$values = '';
$field_value = isset( $data[ $key ] ) ? $data[ $key ] : null;
if ( ! is_null( $field_value ) ) {
$fields_slugs = wp_list_pluck( $form_fields, 'slug' );
$field_key = array_search( $key, $fields_slugs, true );
$field_options = false !== $field_key && ! empty( $form_fields[ $field_key ]->raw['options'] )
? wp_list_pluck( $form_fields[ $field_key ]->options, 'label', 'value' )
: array();
if ( ! isset( $field_options[ $field_value ] ) && isset( $_POST[ $key ] ) ) {
return sanitize_text_field( $_POST[ $key ] );
}
}
}
}
return $content;
},10,3);
Note: Please change 361 to your form’s ID in the code. Also, we are assuming the select field’s ID as select-1 please change that too if it’s different.
You can add the code using a mu-plugin. Please find more details here: https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins
We recommend testing this on the dev/staging version first before putting it on the live site.
Please feel free to get back to us if you need any clarification.
Kind Regards,
Nebu John