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
// 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 to see the link]
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘custom code not working in function.php’ is closed to new replies.