Hi, How to adjust Chris’s solution to do the same but choose the dropdown options sequentially:
// change 638 to your form ID
add_filter( 'gform_pre_render_638', 'set_random_default' );
function set_random_default( $form ) {
foreach( $form['fields'] as &$field ) {
if( 2 === $field->id ) {
GFCommon::log_debug( __METHOD__ . '(): Matched field ID.' );
// count the number of choices, and subtract one, because this is a zero-based array
$count = count ( $field->choices ) -1;
GFCommon::log_debug( __METHOD__ . "(): Number of items in the array is {$count}." );
// select a random integer from 0 to $count
$choice_number = rand ( 0, $count );
GFCommon::log_debug( __METHOD__ . "(): Selected {$choice_number} out of {$count} choices." );
// make that choice 'selected'
$field->choices[$choice_number]['isSelected'] = 1;
}
}
return $form;
}