Title: custom code not working in function.php
Last modified: June 23, 2023

---

# custom code not working in function.php

 *  Resolved [websterfrank](https://wordpress.org/support/users/websterfrank/)
 * (@websterfrank)
 * [2 years, 11 months ago](https://wordpress.org/support/topic/custom-code-not-working-in-function-php/)
 * Please I want to assign a predefined random values to hidden field automaticaly
   in gravity form and I added this code to my function.php but still not working
   could you please help fix this
 *     ```wp-block-code
       // Add this code to your theme's functions.php file or custom plugin
   
       // Define an array of predefined values for the field
       function get_predefined_values() {
           $values = array(
               'Value 1',
               'Value 2',
               'Value 3',
               // Add more values as needed
           );
   
           return $values;
       }
   
       // Assign a random value to the field on entry save
       function assign_random_value($entry, $form) {
           $predefined_values = get_predefined_values();
           $random_value = $predefined_values[array_rand($predefined_values)];
   
           // Replace '2' with the actual field ID of the field you want to assign values to
           $entry['9'] = $random_value;
   
           return $entry;
       }
       add_filter('gform_entry_post_save', 'assign_random_value', 10, 2);
   
       // Populate the field value with the assigned random value
       function populate_random_value($value, $field, $name) {
           // Replace '2' with the actual field ID of the field you want to assign values to
           if ($field->id == 9) {
               $predefined_values = get_predefined_values();
               $random_value = $predefined_values[array_rand($predefined_values)];
   
               return $random_value;
           }
   
           return $value;
       }
       add_filter('gform_field_value', 'populate_random_value', 10, 3);
       ```
   
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fcustom-code-not-working-in-function-php%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Theme Author [Bosa Themes](https://wordpress.org/support/users/bosathemes/)
 * (@bosathemes)
 * [2 years, 10 months ago](https://wordpress.org/support/topic/custom-code-not-working-in-function-php/#post-16874852)
 * Hello,
 * We would like to inform you that our support is primarily focused on assisting
   with theme-related queries and issues. While we strive to provide the best support
   possible, we are unable to offer support for third-party plugins or custom customizations
   for the theme. Our expertise lies in providing assistance and guidance for the
   functionalities and features of our theme.

Viewing 1 replies (of 1 total)

The topic ‘custom code not working in function.php’ is closed to new replies.

 * ![](https://i0.wp.com/themes.svn.wordpress.org/bosa-charity/1.0.4/screenshot.
   png)
 * Bosa Charity
 * [Support Threads](https://wordpress.org/support/theme/bosa-charity/)
 * [Active Topics](https://wordpress.org/support/theme/bosa-charity/active/)
 * [Unresolved Topics](https://wordpress.org/support/theme/bosa-charity/unresolved/)
 * [Reviews](https://wordpress.org/support/theme/bosa-charity/reviews/)

## Tags

 * [gravity form](https://wordpress.org/support/topic-tag/gravity-form/)

 * 1 reply
 * 2 participants
 * Last reply from: [Bosa Themes](https://wordpress.org/support/users/bosathemes/)
 * Last activity: [2 years, 10 months ago](https://wordpress.org/support/topic/custom-code-not-working-in-function-php/#post-16874852)
 * Status: resolved