Sometimes, the types of fields that are available by default in Contact Form 7 are just not enough. And sometimes, you want to just be able to use a shortcode when you define the form . For such situation, we can use the wpcf7_add_shortcode()
function, combined with the wpcf7_init
hook. Continue reading “How to add custom shortcodes in CF7”
Useful hooks in CF7
Contact form 7 has a few hooks that you can use to customize your forms. Here is a list of those hooks that I think are the most helpful. Continue reading “Useful hooks in CF7”
How to correctly get posted data in CF7
In Contact Form 7, if you hook into wpcf7_mail_sent
, then the $_POST
variable is empty, so you cannot use it to do stuff with it. You are too late. However, there is a way to get around this: you have to use Contact Form 7 built-in functions to get the posted data. Continue reading “How to correctly get posted data in CF7”
How to validate a field in CF7
What we need:
- a filter
'wpcf7_validate_{$field_type}'
, which will filter the fields by type; - a function, which takes 2 arguments from Contact Form 7:
$result
, which can be validated or invalidated before it is returned;$tag
, which helps us to identify the field by its name.