Select field – change selected option with code
-
Hi i need to change the selected option in a Select field when the form is load. I tried to use the filter ‘wpcf7_form_tag’ and for text & textarea is working but for Select fields is not.
let’s say i have a Select like this
[select my-select "one" "two" "three"]I want to have the value “three” as default but using code. I try something like this:
function filter_wpcf7_form_tag( $scanned_tag, $replace ) { if($scanned_tag['name'] == 'my-select'){ $values = 'three'; $scanned_tag['values'][] = $values; } return $scanned_tag; } add_filter( 'wpcf7_form_tag', 'filter_wpcf7_form_tag', 10, 2 );But with this code is just adding a new option so finnaly i get something like this
[select my-select "one" "two" "three" "three"]Any idea? Thanks a lot!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Select field – change selected option with code’ is closed to new replies.