toolman Posted October 24, 2012 Share Posted October 24, 2012 Hi, I am trying to validate a mailto link, but its not working. This is the code: mailto:hello@domain.com?subject=my subject here&body=this is the body Any ideas why it is not validating? Thanks Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted October 24, 2012 Share Posted October 24, 2012 What do you mean "validate" it? Normally URLs must be run through urlencode(), but first you have to tell us what you mean by validate. Quote Link to comment Share on other sites More sharing options...
toolman Posted October 24, 2012 Author Share Posted October 24, 2012 When I run it through the WC3 validator, I get this error: Line 99, Column 199: general entity "body" not defined and no default entity Quote Link to comment Share on other sites More sharing options...
Christian F. Posted October 24, 2012 Share Posted October 24, 2012 Ampersands needs to be encoded to their ISO-equivalents, as they're a special HTML character. If you have PHP code that generates this link, then you'll need to use htmlspecialchars () on it. Otherwise, manually escape them. Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted October 24, 2012 Share Posted October 24, 2012 (edited) Show the whole line of HTML source. Are there quotes around the href value? The ampersand should not be encoded, since the link needs to have it in order to work. Edited October 24, 2012 by ManiacDan Quote Link to comment Share on other sites More sharing options...
kicken Posted October 24, 2012 Share Posted October 24, 2012 You're still technically supposed to encode the & inside urls. Browsers don't have any issues if you don't though. href="mailto:hello@domain.com?subject=my+subject+here&body=this+is+the+body" would be correct for the validator and with URL encoding. Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted October 24, 2012 Share Posted October 24, 2012 I could have sworn christian said urlencode, not htmlentities. Yes, htmlentities is "more valid." Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.