Disabling Safari autofill on usernames and passwords

后端 未结 17 1779
萌比男神i
萌比男神i 2020-11-29 03:52

You might already know, that Safari has a nasty autofill bug where it fills email, username and password fields no matter if you set autocomplete=\"off\" or not

17条回答
  •  北荒
    北荒 (楼主)
    2020-11-29 04:13

    My issue: I have a section in an admin area that allows users to set all language values, some of which contain the words "password", "email", "email address" etc. I don't want these values to be filled with the user's details, they are for creating translations into another language. This is then a valid exception to the "circumvent the browser's preference" mentioned.

    My solution: I simply created alternate names:

    $name = str_replace('email','em___l',$name);
    $name = str_replace('password','pa___d',$name);
    
    
    

    Then when the form is posted:

    foreach($_POST as $name=>$value) {
        $name=str_replace('em___l','email',$name);
        $name=str_replace('pa___d','password',$name);
        $_POST[$name]=$value;
    }
    

    This is the only method that worked for me.

提交回复
热议问题