I'm a big fan of Contact Form 7 and I always come to a point where I need to make a few extended customization to my forms. This time, I'm quite frustrated trying to add different classes to a select element <option>
tag with no avail.
What I'm trying to do is implement a cool style and effect to dropdown lists from Here into my own CF7 form - as the screenshot shows it works nicely, however, icons are not showing because so that they can be displayed the <option>
tag within a select element needs to have its own class.
For e.g:
First, I need to create a select element with id="cd-dropdown" and class="cd-select", until here, this can be easily achieved with the CF7 shortcode generator as bellow.
[select* select-profissao id:cd-dropdown class:cd-select "Professional" "Nurse" "Lawyer"]
Contact Form 7 aforementioned shortcode generates the html select element to something like this:
<select id="cd-dropdown" class="cd-select">
<option value="" selected>Professional</option>
<option value="" >Nurse</option>
<option value="" >Lawyer</option>
</select>
But I'd like to be able to add a class to the <option>
tag. Is it even possible to achieve that by using the CF7 shortcode generator? Are there any workarounds in order to achieve that maybe by using javascript/jQuery or even PHP?
<select id="cd-dropdown" class="cd-select">
<option value="" selected>Professional</option>
<option value="" class="icon-nurse">Nurse</option>
<option value="" class="icon-lawyer">Lawyer</option>
</select>
I'd really appreciate any guidance regarding this issue. Thanks in advance.
I think it would be easier to add classes to option client side using jQuery (assuming you are already using jQuery for the SimpleDropDownEffects plugin)
Example Select rendered by contact form:
Add following javascript on the page:
Pros: No hacking into plugin files, no update plugin woes.
Cons: class names are had-coded in js
Just add this jquery: http://jsfiddle.net/rvpatel/7wa3V/
Modify in your plugin dir
modules/select.php
wpcf7_select_shortcode_handler function:Now you can call the plugin as before, or send the value of json(all keys rendered as attribute), i.e.:
Unfortunately I can not test this (No installed wordpress).