Title: Dynamic Population fields cause error
Last modified: May 18, 2023

---

# Dynamic Population fields cause error

 *  Resolved [Robertmurdock](https://wordpress.org/support/users/robertmurdock153/)
 * (@robertmurdock153)
 * [3 years ago](https://wordpress.org/support/topic/dynamic-population-fields-cause-error/)
 * Hello,
 * We are using the country and state fields in the default registration form. We
   have added the call-back function as per the document guide.
 * [https://docs.ultimatemember.com/article/1486-how-to-use-choices-callback](https://docs.ultimatemember.com/article/1486-how-to-use-choices-callback)
 * When we register the new user we are facing the below error.
 * 173.239.214.73:0] PHP Fatal error: Uncaught TypeError: rtrim(): Argument #1 (
   $string) must be of type string, array given in /nas/content/live/testwebiste/
   wp-content/plugins/ultimate-member/includes/core/class-fields.php:3321\nStack
   trace:\n#0 /nas/content/live/testwebiste/wp-content/plugins/ultimate-member/includes/
   core/class-fields.php(3321): rtrim(Array)\n#1 /nas/content/live/testwebiste/wp-
   content/plugins/ultimate-member/includes/core/class-fields.php(4191): um\core\
   Fields->edit_field(‘state_today’, Array)\n#2 /nas/content/live/testwebiste/wp-
   content/plugins/ultimate-member/includes/core/um-actions-register.php(626): um\
   core\Fields->display(‘register’, Array)\n#3 /nas/content/live/testwebiste/wp-
   includes/class-wp-hook.php(308): um_add_register_fields(Array)\n#4 /nas/content/
   live/testwebiste/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters(”,
   Array)\n#5 /nas/content/live/testwebiste/wp-includes/plugin.php(517): WP_Hook-
   >do_action(Array)\n#6 /nas/content/live/testwebiste/wp-content/plugins/ultimate-
   member/templates/register.php(75): do_action(‘um_main_registe…’, Array)\n#7 /
   nas/content/live/testwebiste/wp-content/plugins/ultimate-member/includes/core/
   class-shortcodes.php(290): include(‘/nas/content/li…’)\n#8 /nas/content/live/
   testwebiste/wp-content/plugins/ultimate-member/includes/core/class-shortcodes.
   php(900): um\core\Shortcodes->load_template(‘register’)\n#9 /nas/content/live/
   testwebiste/wp-content/plugins/ultimate-member/includes/core/class-shortcodes.
   php(794): um\core\Shortcodes->template_load(‘register’, Array)\n#10 /nas/content/
   live/testwebiste/wp-content/plugins/ultimate-member/includes/core/class-shortcodes.
   php(564): um\core\Shortcodes->load(Array)\n#11 /nas/content/live/testwebiste/
   wp-includes/shortcodes.php(355): um\core\Shortcodes->ultimatemember(Array, ”,‘
   ultimatemember’)\n#12 [internal function
 * Country: 
   [https://share.getcloudapp.com/ApuvZZDA](https://share.getcloudapp.com/ApuvZZDA)
   [https://share.getcloudapp.com/P8u2JJ2l](https://share.getcloudapp.com/P8u2JJ2l)
 * State:
   [https://share.getcloudapp.com/NQuWyyW8](https://share.getcloudapp.com/NQuWyyW8)
   [https://share.getcloudapp.com/JrupKKeZ](https://share.getcloudapp.com/JrupKKeZ)
 * 
   Can you please help us with this?
 * Thanks
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fdynamic-population-fields-cause-error%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  [missveronica](https://wordpress.org/support/users/missveronicatv/)
 * (@missveronicatv)
 * [3 years ago](https://wordpress.org/support/topic/dynamic-population-fields-cause-error/#post-16749475)
 * [@robertmurdock153](https://wordpress.org/support/users/robertmurdock153/)
 * You can try this code snippet:
 *     ```
       function custom_umwoo_country_list_dropdown() {
   
           $countries = WC()->countries->get_countries();
           return $countries;
       }    
       function custom_umwoo_get_states_dropdown() {
   
           $country_code = sanitize_text_field( $_POST['parent_option'] );
           $valid_states = WC()->countries->get_states( $country_code );
   
           return $valid_states;
       }
       ```
   
 *  Plugin Support [Yurii](https://wordpress.org/support/users/yuriinalivaiko/)
 * (@yuriinalivaiko)
 * [3 years ago](https://wordpress.org/support/topic/dynamic-population-fields-cause-error/#post-16752265)
 * Hello [@robertmurdock153](https://wordpress.org/support/users/robertmurdock153/)
 * This error appears because you use the wrong way to get states. Fix mistakes 
   in your code:
    - use a proper way to get countries array: `WC()->countries->get_countries()`
    - use a proper way to get states array: `WC()->countries->get_states( $cc )`
 * Try this code:
 *     ```wp-block-code
       function custom_umwoo_country_list_dropdown() {
       	$countries = WC()->countries->get_countries();
       	return $countries;
       }
       function getStates() {
       	if ( ! empty( $_POST['parent_option'] )&& is_string( $_POST['parent_option'] ) ) {
       		$cc     = sanitize_text_field( $_POST['parent_option'] );
       		$states = WC()->countries->get_states( $cc );
       	}
       	return empty( $states ) ? array() : $states;
       }
       ```
   
 * Regards
 *  Plugin Support [andrewshu](https://wordpress.org/support/users/andrewshu/)
 * (@andrewshu)
 * [3 years ago](https://wordpress.org/support/topic/dynamic-population-fields-cause-error/#post-16775886)
 * Hi [@robertmurdock153](https://wordpress.org/support/users/robertmurdock153/)
 * This thread has been inactive for a while so we’re going to go ahead and mark
   it Resolved.
 * Please feel free to re-open this thread if any other questions come up and we’d
   be happy to help. 🙂
 * Regards

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

The topic ‘Dynamic Population fields cause error’ is closed to new replies.

 * ![](https://ps.w.org/ultimate-member/assets/icon-256x256.png?rev=3160947)
 * [Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin](https://wordpress.org/plugins/ultimate-member/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ultimate-member/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ultimate-member/)
 * [Active Topics](https://wordpress.org/support/plugin/ultimate-member/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ultimate-member/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ultimate-member/reviews/)

 * 3 replies
 * 4 participants
 * Last reply from: [andrewshu](https://wordpress.org/support/users/andrewshu/)
 * Last activity: [3 years ago](https://wordpress.org/support/topic/dynamic-population-fields-cause-error/#post-16775886)
 * Status: resolved