简体   繁体   中英

Ways to remove the autocomplete of an input box

I need a text input field which does not use the autocomplete function - If a user has submitted the form before, his previous submissions should -not- appear as he types into the form again, even if he is typing the same thing again. As far as I can tell, there are a few ways to do this:


However, I believe this is a proprietary tag, and I am not sure how compatible it is across browsers


One could even use JS to set the name back to an expected value before submission. However, if the user does not have JS installed, you'd need another hidden input with the name - and the php code on the other side gets messy fast.

Do you know of any other ways? Is one of these ways the "accepted" way? Comments?

Thanks,
Mala

Stick with the random name. You can do it simply enough server and client and you meet your no-js requirement.

You can store the original and changed name in a $_SESSION variable before outputting the form, and after the user submits, just get the name from there:

$random_name = md5('original_name' . time());
$_SESSION['original_name'] = $random_name;

...output form...

And after submitting you can easily get the value from $_POST using the $_SESSION variable:

$field_value = $_POST[$_SESSION['original_name']];

Just be sure that you have sessions available by calling session_start() before any processing.

自动完成是浏览器决定自己做的事情,因此肯定没有要查看的规范文档。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM