Getting Default Values from Shortcode Attributes
-
Hi,
I would like to set a default value as input value. How to do that is explained in this article
https://contactform7.com/getting-default-values-from-shortcode-attributes/
The article uses an email input field type to demonstrate how this works.
I have tested this and it works fine for email and text fields (probably also on some other input types, but I haven’t tested all). So far, so good.
Where it does not seem to work is for the input field type file.
I’ve added the default:shortcode_attr option to my form-tag:
[file* filename default:shortcode_attr]
I then added an attribute with the same name as the field (“filename”) into the shortcode for the contact form with value example_image.jpg:
[contact-form-7 id="123" title="Contact Form" filename="example_image.jpg"]
And I’ve added the following code snippet to my theme’s functions.php file:
add_filter( 'shortcode_atts_wpcf7', 'custom_shortcode_atts_wpcf7_filter', 10, 3 ); function custom_shortcode_atts_wpcf7_filter( $out, $pairs, $atts ) { $my_attr = 'filename'; if ( isset( $atts[$my_attr] ) ) { $out[$my_attr] = $atts[$my_attr]; } return $out; }
By doing so I would expect to see ‘example_image.jpg’ as value in the file input field. But that does not happen. It stays empty.
Anyone has an idea why it does not work for input type file and how to make it work for input type file?
The page I need help with: [log in to see the link]
- The topic ‘Getting Default Values from Shortcode Attributes’ is closed to new replies.