Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm using HTML5 on two sites running two different versions of WordPress. They both exhibit the same behaviour and I would like some help with fixing this please.

<label for="url">Website</label> <input type="url" name="url" id="url" value="<?php echo esc_attr($comment_author_url); ?>" placeholder="Enter Website Address (optional)" pattern="https?://.+">

In testing, we have identified a problem with comment_author_url that occurs when people do not input an URL. For some reason, WordPress is picking up the placeholder text and saving it into the database, like so:

http://EnterWebsiteAddress(optional)

I'm having real trouble trying to identify why this is happening. The placeholder attribute isn't inside the input value so should not be getting picked up. This same code is being used in other applications without problems.

Does anyone know how to correct this in WordPress?

UPDATE: I've done considerable research on this and thought I'd share my findings. The issues come from the comment_form function within WordPress itself.

To avoid the problems there are two options:

  1. Only use placeholders on required fields. When the fields get focus and something is input the placeholder gets cleared.
  2. Use JavaScript to clear placeholders before the form is submitted.

I hope this helps the others that have run into the same issues. I'm not submitting a patch to WordPress because, at this time, WordPress only intends to support XHTML.

share|improve this question
    
Cannot reproduce (Firefox, Opera). Had you tried different browsers and does it make a difference? –  Rarst Jan 27 '11 at 14:35
    
Please name the browser and version. Are you sure this is a WordPress related problem? –  hakre Jan 28 '11 at 1:33
    
Similar post to the hackers list, which gained some valuable feedback.. lists.automattic.com/pipermail/wp-hackers/2011-January/… –  t31os Jan 28 '11 at 14:35
    
Same issue but the feedback wasn't much good since the sites have no JavaScript added at this stage. Ultimately, they will have js to support older browsers but its definitely not a js problem. The behaviour is occurring with Opera 11, IE7 & IE8, and Firefox 3.6.13. Chrome and Safari seem to be ok. –  Elpie Jan 30 '11 at 13:07
add comment

2 Answers

I am also having this issue, haven't found any solutions for it, apart from just plain 'ol removing the placeholder attribute : / it seems to occur in any browser. I am using a JavaScript fallback for browsers that dont support the placeholder attrib, but with or without it, wordpress seems to pick up the placeholder text as the value for the input.

share|improve this answer
    
Use JavaScript for all browsers, not just as a fallback. Make sure the script clears placeholders on submit. Until WordPress moves away from only supporting XHTML in the core this is the only way to clear those placeholders without hacking the core. –  Elpie May 10 '11 at 15:25
add comment
up vote 1 down vote accepted

To avoid the problems there are currently only two options:

  1. Only use placeholders on required fields. When the fields get focus and something is input the placeholder gets cleared.
  2. Use JavaScript to clear placeholders before the form is submitted.

Note: Answered my own question after much research.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.