Support » Plugin: Bootstrap for Contact Form 7 » select tags do not pre-fill default option

  • Roy

    (@lev0)


    Default was set as POST fields (not a form submission) but were not being pre-filled correctly on <select> elements. To make it behave the same as the CF7 plugin I had to patch it like so:

    
    --- a/modules/select.php
    +++ b/modules/select.php
    @@ -111,24 +111,11 @@
     	}
     	$posted = wpcf7_is_posted();
     
    +	$hangover = (array) wpcf7_get_hangover( $tag->name, $default_choice );
     	foreach ( $values as $key => $value ) {
     		$options[ $value ] = isset( $labels[ $key ] ) ? $labels[ $key ] : $value;
     
    -		if ( $posted && !empty( $post ) ) {
    -			if ( $multiple && in_array( esc_sql( $value ), (array) $post ) ) {
    -				$selected[] = $value;
    -			}
    -			if ( ! $multiple && $post == esc_sql( $value ) ) {
    -				$selected = $value;
    -			}
    -		} elseif ( isset( $get ) && !empty( $get ) ) {
    -			if ( $multiple && in_array( esc_sql( $value ), (array) $get ) ) {
    -				$selected[] = $value;
    -			}
    -			if ( ! $multiple && $get == esc_sql( $value ) ) {
    -				$selected = $value;
    -			}
    -		} elseif ( ! $shifted && in_array( (int) $key + 1, (array) $defaults ) || $shifted && in_array( (int) $key, (array) $defaults ) ) {
    +		if ( in_array( $value, $hangover, true ) ) {
     			if ( $multiple ) {
     				$selected[] = $value;
     			} else {
    
    • This topic was modified 5 months ago by Roy.
    • This topic was modified 5 months ago by Steve Stern.
  • You must be logged in to reply to this topic.