Starting with version 4.9 of WPCF7, adaptation of the answer above so as not to lose error messages:
First of all, in the editor on the CMS, wrap your input field and any other elements that you want to group, for example:
<span class="wpcf7-form-control-wrap your-name">{field codes, etc, here}</span>
Note that you will need to use the class "wpcf7-form-control-wrap" and the class corresponding to your field name.
Then use this regex code in functions.php . Adaptation may be required for your specific needs.
add_filter('wpcf7_form_elements', function($content) { preg_match_all('/<(span).*?class="\s*(?:.*\s)?wpcf7-form-control-wrap(?:\s[^"]+)?\s*"[^\>]*>(.*)<\/\1>/i', $content,$matches); foreach($matches[2] as $match): $content = str_replace(trim($match),trim(preg_replace('/<(span).*?class="\s*(?:.*\s)?wpcf7-form-control-wrap(?:\s[^"]+)?\s*"[^\>]*>(.*)<\/\1>/i', '\2', $match)),$content); endforeach; return $content; });
This will split the span tag around the input field, leaving your new span tag intact. The effect is to essentially move the span tag only from the input field to be around any elements you want to wrap.
The reason for this is that the code for submitting the form, unfortunately, is very hardcoded. To have complete freedom over the structure of your HTML, you need to either:
Change the rest-api.php code around line 295 to change the value of "in" to something less specific. Naturally, this is not a recommended route, although one that gives you complete freedom to structure your content as you wish. It will be overwritten by plugin updates.
foreach ( (array) $result['invalid_fields'] as $name => $field ) { $invalid_fields[] = array( 'into' => 'span.wpcf7-form-control-wrap.' . sanitize_html_class( $name ), 'message' => $field['reason'], 'idref' => $field['idref'], ); }
Click on wpcf7: invalid event and run your own result verification code. Needless to say, this duplicates most of the work that the plugin already does for you when accepting (so far) the use of the span tag with the class "wpcf7-form-control-wrap" in the manner described above preserves all the functionality of the plugin, canceling one of the most annoying hard plugin encodings.
niaccurshi
source share