Codeigniter:Chrome自动填充导致提交后输入框值变更问题
Ah, I feel your pain—browser auto-fill can be incredibly stubborn, especially when it messes with password fields that shouldn’t get pre-filled. Let’s walk through a couple of reliable solutions tailored to your CodeIgniter form:
1. Use the Standard autocomplete="new-password" Attribute
Modern browsers (including Chrome) recognize the new-password value for the autocomplete attribute as a signal that this field is for setting a new password, not logging in. This tells Chrome to skip filling it with saved credentials.
Modify your password input field like this:
<input type="password" id="inputPasswd" name="password" placeholder="New password" value="" autocomplete="new-password">
This is the most clean and standards-compliant approach, so it should be your first try.
2. Add a "Decoy" Hidden Password Field
If Chrome still ignores the new-password attribute (it can happen in some edge cases), you can trick it by adding a hidden password field before your real one. Chrome will fill this decoy field instead of your actual password input.
Update your form like so:
<form action="<?php echo site_url("Manage/changeUserPassword"); ?>" method="post"> <input hidden class="inputwithiduser" type="text" name="iduser" value=""> <!-- Decoy field to catch auto-fill --> <input type="password" style="position: absolute; left: -9999px; top: -9999px;" name="fake_password" autocomplete="off"> <input type="password" id="inputPasswd" name="password" placeholder="New password" value="" autocomplete="new-password"> <button type="submit">Save...</button> </form>
We use absolute positioning to move the decoy off-screen instead of display: none because some browsers ignore hidden fields when handling auto-fill.
Why autocomplete="off" Often Fails
You might have tried setting autocomplete="off" before, but Chrome intentionally ignores this for password fields in most cases (to prioritize user convenience). That’s why using new-password or the decoy method is more effective.
Give these solutions a shot—one of them should stop Chrome from messing with your password input after submission.
内容的提问来源于stack exchange,提问作者Luca4k4

