Question

So, it has come to my attention that Google decided to remove functionality for HTML's autocorrect="off" so no matter if you use this on your form, or individual element's Google Chrome still show autocompleted data fill.

So, puzzling aroud, I couldn't think of a way how to fix this, and then I figured it out! (see below)

Was it helpful?

Solution

If your input has a value, then autocomplete won't over-rule you and put user's data in!

So for instance: <input type="text" name="username" value=" "> - Notice the space inbetween value?

Now, if you're entering this data into a database, make sure you make use of PHP's own trim() function to remove any whitespace! - Or do a str_replace on the string!

So, for instance, here is what I have to check if my input exists (OOP, not procedural!)

if(!Input::get('username')) {
    $user_name = ' ';
} else { 
    $user_name = escape(Input::get('username'));
}

So, you can see, I am checking to see if there is a value in my textbox and if there isn't I am setting the variable $user_name to a blank space, and if there is, for my functionality, I will output the username they entered.

Please Note: My input after else { is wrapped in an escape() function, this is a function I have made to prevent against invalid data/queries being entered into the string to create a SQL injection.

Procedural code would look along the lines of this:

if(!$_GET['username']) {
    $user_name = ' ';
} else {
    $user_name = $_GET['username'];
}

Hope this helps some of you!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top