├── .gitignore ├── README.md ├── readme.txt └── cf7-simple-hidden-field.php /.gitignore: -------------------------------------------------------------------------------- 1 | _notes 2 | .DS_Store 3 | *.LCK 4 | *.svn 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Contact Form 7 - Simple Hidden Field 2 | ==================================== 3 | 4 | Add simple & dynamic hidden fields in Contact Form 7 5 | 6 | See readme.txt 7 | 8 | # Adopt my Contact Form 7 (CF7) Plugins 9 | 10 | I am putting my 3 CF7 plugins up for adoption. 11 | 12 | The reasons for this are: 13 | * I no longer use CF7 for my clients. 14 | * It is too difficult to use for my average client 15 | * It does not support the features my clients want 16 | * The authour of CF7 makes too many backwards compatibility breaking changes 17 | * I simply do not have time to keep up with maintenence for plugins I no longer use 18 | 19 | These plugins do have users and are usefull for those that use CF7 and I'd rather someone else takes them over than let them die. 20 | 21 | The 3 plugins involved are: 22 | * At WP 23 | * [Dynamic Select for Contact Form 7](https://wordpress.org/plugins/contact-form-7-dynamic-select-extension/) 24 | * [Hidden Field for Contact Form 7](https://wordpress.org/plugins/contact-form-7-simple-hidden-field/) 25 | * [Dynamic Recipient for Contact Form 7](https://wordpress.org/plugins/contact-form-7-dynamic-mail-to/) 26 | * On Github 27 | * [Dynamic Select for Contact Form 7](https://github.com/Hube2/contact-form-7-dynamic-select-extension) 28 | * [Hidden Field for Contact Form 7](https://github.com/Hube2/contact-form-7-simple-hidden-field) 29 | * [Dynamic Recipient for Contact Form 7](https://github.com/Hube2/contact-form-7-dynamic-mail-to) 30 | 31 | These plugins were built to work togther 32 | * The dynamic select to populate drop downs 33 | * The dynamic recipient send emails to different people 34 | * The hidden field to supply the fields that the recipient plugin needs to work 35 | 36 | If you are interested in adopting all 3 of these plugins please open up an issue in any of the Github repos for any of these plugins. Below is how I would like to do this, if you have other ideas you can bring them up when you open the issue. 37 | 38 | * You fork all of these repos 39 | * You maintian, update and improve these plugins as needed an send me pull requests 40 | * You take over supporting these plugins on Github and WP (answer questions etc) 41 | * I will, for a short time continue to update the WP repo with your changes 42 | * At some time in the future I will transfer ownership of the both the Github and WordPress repos to you. -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === Hidden Field for Contact Form 7 === 2 | Contributors: Hube2 3 | Tags: adopt-me, contact form 7 simeple hidden field 4 | Requires at least: 4.0 5 | Tested up to: 4.9 6 | Stable tag: 2.0.2 7 | Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=hube02%40earthlink%2enet&lc=US&item_name=Donation%20for%20WP%20Plugins%20I%20Use&no_note=0&cn=Add%20special%20instructions%20to%20the%20seller%3a&no_shipping=1¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted 8 | License: GPLv2 or later 9 | License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 | 11 | Add simeple hidden fields in Contact Form 7 12 | 13 | 14 | == Description == 15 | 16 | Addopt this plugin. [Please see details on Github](https://github.com/Hube2/contact-form-7-simple-hidden-field). 17 | 18 | Create simple hidden fields and dynamically generated hidden fields with Conact Form 7 19 | 20 | Simple Hidden fields are just that, simple hidden fields 21 | 22 | *** New Dynamic Hidden Fields *** 23 | 24 | How to create dynamic hidden fields 25 | 26 | 1) Create a filter to be called from your CF7 Dynamic Select Field. 27 | 28 | Example Filter: 29 | 30 | `function cf7_dynamic_hidden_do_example1($value, $args=array()) { 31 | $value = 'new value'; 32 | return $value; 33 | } // end function cf7_dynamic_select_do_example1 34 | add_filter('wpcf7_dynamic_hidden_example1', 35 | 'cf7_dynamic_hidden_do_example1', 10, 2);` 36 | 37 | 2) Enter the filter name and any arguments into the Filter Field when adding a Dynamic Hidden Field. 38 | For example, if we need to supply a post_id so that the filter can get the post title 39 | filter value entered would look something like this: 40 | 41 | `my-filter post_id=9` 42 | 43 | ***Do Not Include any extra spaces or quotes arround values, names or the =*** 44 | 45 | You can pass any number are arguments to your filter and they will be converted into an array. For example the 46 | following: 47 | 48 | `my-filter post_id=101 author_id=2` 49 | 50 | This will call the function assocaited with the filter hook 'my-filter' with an arguments the argument array of: 51 | `$args = array( 52 | 'post_id' => 101, 53 | 'author_id' => 2 54 | )` 55 | 56 | If the filter does not exist or your filter does not return a value then the value of the hidden field will be left empty. 57 | 58 | [Also on GitHub](https://github.com/Hube2/contact-form-7-simple-hidden-field) 59 | 60 | == Installation == 61 | 62 | 1. Upload the files to the plugin folder of your site 63 | 2. Activate it from the Plugins Page 64 | 65 | 66 | == Screenshots == 67 | 68 | 69 | == Frequently Asked Questions == 70 | 71 | = Why Filters? = 72 | 73 | Many other plugins of this type use shortcodes. I'm not a real fan of shortcodes, but that's not the only 74 | reason. 75 | 76 | Filters are much more flexible that shortcodes. 77 | 78 | For example, a shortcode cannot return an array. A shortcode pretty much requires that only a text value is returned. 79 | 80 | 81 | == Changelog == 82 | 83 | = 2.0.2 = 84 | * corrected to work with CF7 >= 4.8 85 | 86 | = 2.0.1 = 87 | * corrected fatal function call error due to update in CF7 88 | 89 | = 2.0.0 = 90 | * Replaced depricated CF7 function calls 91 | 92 | = 1.2.1 = 93 | 94 | * Corrected a bug, incorrect field type name for dynamic hidden field when creating new field, introduced in 1.2.0 95 | 96 | = 1.2.0 = 97 | 98 | * Updated tag page to be completely compatible w/ CF7 >= V4.2 99 | * Backwards compatible w/ CF7 < V4.2 100 | 101 | = 1.1.3 = 102 | 103 | * Updated to work with CF7 V4.2 (tag pane still needs some work to make it 100% but it can be used and it will still work with previous versions of CF7) 104 | 105 | = 1.1.2 = 106 | 107 | * Added ability to preset value with query string 108 | 109 | = 1.1.1 = 110 | 111 | * Added autocomplete="off" attribute to all hidden fields 112 | 113 | = 1.1.0 = 114 | 115 | * Added Dynamic Hidden Field 116 | 117 | = 1.0.0 = 118 | 119 | * initial release -------------------------------------------------------------------------------- /cf7-simple-hidden-field.php: -------------------------------------------------------------------------------- 1 | '; 67 | return $html; 68 | } // end public function shortcode_handler 69 | 70 | public function dynamic_shortcode_handler($tag) { 71 | // generates html for form field 72 | $tag_o = $tag; 73 | if (is_a($tag, 'WPCF7_FormTag')) { 74 | $tag = (array)$tag; 75 | } 76 | $name = $tag['name']; 77 | if (empty($name)) { 78 | return ''; 79 | } 80 | $wpcf7_contact_form = WPCF7_ContactForm::get_current(); 81 | // most attributes not really needed, not included 82 | $name_att = $name; 83 | $filter = ''; 84 | $filter_args = array(); 85 | $filter_string = ''; 86 | $values = $tag['values']; 87 | if (isset($values[0])) { 88 | $filter_string = $values[0]; 89 | } 90 | //echo $filter_string; 91 | if ($filter_string != '') { 92 | $filter_parts = explode(' ', $filter_string); 93 | $filter = trim($filter_parts[0]); 94 | $count = count($filter_parts); 95 | for($i=1; $i<$count; $i++) { 96 | if (trim($filter_parts[$i]) != '') { 97 | $arg_parts = explode('=', $filter_parts[$i]); 98 | if (count($arg_parts) == 2) { 99 | $filter_args[trim($arg_parts[0])] = trim($arg_parts[1], ' \''); 100 | } else { 101 | $filter_args[] = trim($arg_parts[0], ' \''); 102 | } 103 | } // end if filter part 104 | } // end for 105 | } // end if filter string 106 | $value = ''; 107 | if ($filter != '') { 108 | $value = apply_filters($filter, $value, $filter_args); 109 | } 110 | $atts = ' name="'.$name.'" value="'.$value.'" autocomplete="off"'; 111 | $html = ''; 112 | return $html; 113 | } // end public function shortcode_handler 114 | 115 | public function validation_filter($result, $tag) { 116 | // validates field on submit 117 | // not required, it's a simple hidden field 118 | return $result; 119 | } // end public function validation_filter 120 | 121 | public function add_tg_generator() { 122 | // called on init to add the tag generator or cf7 123 | // wpcf7_add_tag_generator($name, $title, $elm_id, $callback, $options = array()) 124 | if (!function_exists('wpcf7_add_tag_generator')) { 125 | return; 126 | } 127 | $name = 'simplehidden'; 128 | $title = __('Simple Hidden Field', 'wpcf7'); 129 | $elm_id = 'wpcf7-tg-pane-simplehidden'; 130 | $callback = array($this, 'simple_tg_pane'); 131 | wpcf7_add_tag_generator($name, $title, $elm_id, $callback); 132 | $name = 'dynamichidden2'; 133 | $title = __('Dynamic Hidden Field', 'wpcf7'); 134 | $elm_id = 'wpcf7-tg-pane-dynamichidden2'; 135 | $callback = array($this, 'dynamic_tg_pane'); 136 | wpcf7_add_tag_generator($name, $title, $elm_id, $callback); 137 | } // end public function add_tag_generator 138 | 139 | public function simple_tg_pane($form, $args = '') { 140 | // output the code for CF7 tag generator 141 | if (class_exists('WPCF7_TagGenerator')) { 142 | // tag generator for CF7 >= v4.2 143 | $args = wp_parse_args( $args, array() ); 144 | $desc = __('Generate a form-tag for a Simple Hidden field. For more details, see %s.'); 145 | $desc_link = ''.__( 'Contact Form 7 - Simple Hidden Field').''; 146 | ?> 147 |