jamesallardice / Placeholders.js

A JavaScript polyfill for the HTML5 placeholder attribute
http://jamesallardice.github.io/Placeholders.js
948 stars 232 forks source link

Placeholders Submitted as Value #75

Open john-cheesman opened 10 years ago

john-cheesman commented 10 years ago

If a form is submitted with fields that have not been completed, the placeholder text is submitted as their value. Is it possible to remove the placeholders on submit to prevent them from being submitted?

RobQuistNL commented 10 years ago

This. Very much this. Came here to check this issue.

RobQuistNL commented 10 years ago

I've had this happen on IE11 on Win7

RobQuistNL commented 10 years ago

@john-cheesman I've fixed it by making sure that IE11 doesn't run on IE8 compatibility mode. It works for IE8 and not for 11 in comp. mode.

olefredrik commented 9 years ago

+1 Having the same issue in Win7 IE9. The placeholder text is occasionally inserted as value when form is submitted.

vikuseth commented 9 years ago

Is there any fix for this ?

RobQuistNL commented 9 years ago

This project seems kinda dead.

jamesallardice commented 9 years ago

I will get around to investigating this. There is already code in there to remove placeholders before form submission but clearly there's a bug with it somewhere. I'm more than happy to accept pull requests should anyone like to take a look.

@RobQuistNL The project isn't dead, just slow-moving. Mainly because I'm busy with other things but also because this project should be becoming less and less necessary. Browser support for the placeholder attribute is strong and it's only really IE9 and below that this is now helpful for. Since I don't have to support IE9 or below in any of my projects this ends up taking a back seat. As mentioned previously, I'm always happy to accept pull requests.

RobQuistNL commented 9 years ago

Ah right, sorry @jamesallardice - i had that idea because of the old commits and responses. You're right that this is less and less useful.

@vikuseth for the time being you could try to fix it server-side?

apokryfos commented 9 years ago

Not sure if this is the appropriate issue to post in, but when using the Zebra datepicker plugin in IE 8 or IE 9, the placeholder text is submitted as the value. Not sure if the bug is in Zebra or in this plugin, but the Zebra plugin without the placeholders plugin doesn't show placeholders on IE 8 and IE 9 at all so I am guessing the surprise input is coming from here.

littletijn commented 9 years ago

I found the problem within the function newElement( elem ). In this function there is a check:

var form = elem.form;
if ( form && typeof form === 'string' ) {

The property elem.form is the actual form for me. So I modified the check:

var form = elem.form;
if (form) {

Then I removed the line:

// Get the real form.
form = document.getElementById(form);

because form now already contains the actual form. After this, the placeholders get removed on submit correctly and are not POST-ed by the form.

rmorrin commented 8 years ago

@jamesallardice Can you confirm the fix provided by @littletijn is safe to use? I've tried what is suggested and it does seem to resolve the issue.

Probocop7 commented 8 years ago

I've also just tried the above fix, and it does indeed seem resolve the issue.

rmorrin commented 8 years ago

Looks like there are no ill-effects when using this fix (and reading the code, it looks to have been an innocent oversight). @littletijn do you want to submit a PR for this? If no, I am happy to put one together myself, crediting where necessary.

littletijn commented 8 years ago

Whoops. I forgot I had this fix on GitHub. I just found the e-mail for the replies on this issue. Thanks for making the commit on behalf of me.

pihug12 commented 8 years ago

@jamesallardice Can you, please, put up a 4.0.2 build with this fix? It's really needed for IE9.

Many thanks @littletijn & @rmorrin for the fix! :+1: