Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it’s on-topic for WordPress Development Stack Exchange.
Closed last year .
I have below code for contact form 7. Usually I use autocomplete="off"
for html input field. However not able to figure out how to do the same for contact form 7
<div class="row">
<div class="col-md-6">
[text* FirstName placeholder "First Name"]
</div>
<div class="col-md-6">
[text* LastName placeholder "Last Name"]
</div>
<div class="col-md-12">
[email* EmailAddress placeholder "Email Address"]
</div>
<div class="col-md-12">
[text* desc placeholder "Tell us a bit about yourself..."]
</div>
<div class="col-md-12">
[submit "Submit"]
</div>
</div>
Autocomplete tag in form settings does not work anymore (as today Contact Form 7 plugin version 5.1.3
.
The only solution which worked for me was to add custom attributes thanks to https://stackoverflow.com/a/46316728/1720476.
E.g. if You have FirstName
and LastName
fields, where You want to disable autocomplete.
Add this into functions.php
file:
add_filter( 'wpcf7_form_elements', 'imp_wpcf7_form_elements' );
function imp_wpcf7_form_elements( $content ) {
$str_pos = strpos( $content, 'name="FirstName"' );
if ($str_pos) {
$content = substr_replace( $content, ' autocomplete="both" autocomplete="off" ', $str_pos, 0 );
}
$str_pos = strpos( $content, 'name="LastName"' );
if ($str_pos) {
$content = substr_replace( $content, ' autocomplete="both" autocomplete="off" ', $str_pos, 0 );
}
return $content;
}