Split from #675348: META: Support HTML5 form input elements to add a new 'emailfield' Form API element.

Questions:
1. Do we add validation?
2. Do we add any field formatters for this new type (or put as followup)?

CommentFileSizeAuthor
#74 1174620-html5-email-fixup-testcoverage-74.patch2.39 KBNiklas Fiekas
#74 1174620-interdiff-74.txt773 bytesNiklas Fiekas
#71 1174620-html5-email-fixup-testcoverage-71.patch2.39 KBNiklas Fiekas
#63 1174620-html5-email-63.patch19.63 KBNiklas Fiekas
#63 1174620-interdiff-63.txt860 bytesNiklas Fiekas
#59 1174620-html5-email-59.patch19.29 KBNiklas Fiekas
#59 1174620-interdiff-59.txt628 bytesNiklas Fiekas
#56 1174620-html5-email-54.patch19.11 KBNiklas Fiekas
#56 1174620-interdiff-54.txt523 bytesNiklas Fiekas
#57 1174620-html5-email-56.patch19.28 KBNiklas Fiekas
#57 1174620-interdiff-56.txt1.97 KBNiklas Fiekas
#54 1174620-html5-email-54.patch19.11 KBNiklas Fiekas
#54 1174620-interdiff-54.txt523 bytesNiklas Fiekas
#51 1174620-html5-email-51.patch19.09 KBNiklas Fiekas
#51 1174620-interdiff-51.txt1.86 KBNiklas Fiekas
#47 1174620-html5-email-47.patch18.64 KBNiklas Fiekas
#47 1174620-interdiff-47.txt598 bytesNiklas Fiekas
#45 1174620-html5-email-45.patch18.61 KBericduran
#44 1174620-html5-email-44.patch19.46 KBNiklas Fiekas
#44 1174620-interdiff-44.txt2.61 KBNiklas Fiekas
#39 1174620-html5-email-39.patch18.03 KBNiklas Fiekas
#39 1174620-interdiff-39.txt3.05 KBNiklas Fiekas
#38 1174620-html5-email-38.patch14.98 KBNiklas Fiekas
#38 1174620-interdiff-38.txt2.63 KBNiklas Fiekas
#13 1174620-html5-email-element.patch13 KBDave Reid
#10 1174620-html5-email-element.patch13 KBDave Reid
#8 1174620-html5-email-element.patch12.95 KBDave Reid
#7 1174620-html5-email-element.patch12.34 KBDave Reid
#6 1174620-html5-emailfield.patch12.38 KBDave Reid
#3 1174620-html5-emailfield.patch12.43 KBDave Reid
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Issue tags: +html5

1. I think we run it through valid_email_address in the default validator.
2. Follow-up separate issue.

Dave Reid’s picture

Assigned: Unassigned » Dave Reid
Dave Reid’s picture

Status: Active » Needs review
FileSize
12.43 KB

Initial patch, based on the branch '1174620-html5-emailfield' from http://drupal.org/sandbox/davereid/1086890

Status: Needs review » Needs work

The last submitted patch, 1174620-html5-emailfield.patch, failed testing.

Dave Reid’s picture

Todos:
1. Figure out why this fails install
2. Seven theme lacks styling.

Dave Reid’s picture

Renamed element to 'email' from 'emailfield' as per #675348-53: META: Support HTML5 form input elements.

Dave Reid’s picture

Dave Reid’s picture

Status: Needs work » Needs review
FileSize
12.95 KB

Status: Needs review » Needs work

The last submitted patch, 1174620-html5-email-element.patch, failed testing.

Dave Reid’s picture

Status: Needs work » Needs review
FileSize
13 KB

Duh, the element needs the default #element_validate...

Status: Needs review » Needs work

The last submitted patch, 1174620-html5-email-element.patch, failed testing.

Dave Reid’s picture

Um, so I tested on a clean D8 checkout + patch and it installed just fine for me. I am not sure what is up.

Dave Reid’s picture

Status: Needs work » Needs review
FileSize
13 KB

So let's try this one more time.

Status: Needs review » Needs work
Issue tags: -html5

The last submitted patch, 1174620-html5-email-element.patch, failed testing.

Dave Reid’s picture

Status: Needs work » Needs review

#13: 1174620-html5-email-element.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +html5

The last submitted patch, 1174620-html5-email-element.patch, failed testing.

Ralt’s picture

Hi,

Why is it necessary to run the validation through valid_email_address since HTML5's validation is automatic? Older browsers' support?

Dave Reid’s picture

@Ralt: Correct, for HTML5-enabled browsers the validation will happen in the browser, and then double-checked on the server side to support any non-HTML5 supporting browsers.

Jacine’s picture

@Dave Reid question for ya: How are we going to deal with the multiple attribute? I ask because the select element has a specific #multiple property for this, and the multiple attribute is allowed (even if it's not implemented yet) on all of these new input elements, including the e-mail type.

Dave Reid’s picture

I feel like the multiple attribute needs to be its own separate issue because we already provide the 'duplicate' functionality in Field API's 'multiple value' feature which could possibly be cleaned up to support it. Either way it requires a lot more discussion and work. Note that using $form['emailelement']['#multiple'] = TRUE doesn't actually work right now.

Jacine’s picture

Okay, sure. I was just wondering. Thanks! ;)

Dave Reid’s picture

Status: Needs work » Needs review
Issue tags: -html5

#13: 1174620-html5-email-element.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 1174620-html5-email-element.patch, failed testing.

rfay’s picture

Status: Needs work » Needs review

#13: 1174620-html5-email-element.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +html5

The last submitted patch, 1174620-html5-email-element.patch, failed testing.

rfay’s picture

Status: Needs work » Needs review

Puppet turned the change off, so fixed and trying again.

rfay’s picture

Issue tags: -html5

#13: 1174620-html5-email-element.patch queued for re-testing.

rfay’s picture

#13: 1174620-html5-email-element.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +html5

The last submitted patch, 1174620-html5-email-element.patch, failed testing.

rfay’s picture

Well, it does look like progress. Looks like this is a valid result?

quicksketch’s picture

Issue tags: +Needs tests

Unfortunately, you guys will probably find quite quickly that SimpleTest does not support setting POST values on fields of type="email" (or any other HTML5 elements), at least in my testing. We're doing the same thing over in the Webform issue queue and I'm not having the most luck with tests so far. In any case, we need to test the e-mail field specifically to make sure it's working as expected.

ericduran’s picture

As mention by @quicksketch simpletest doesn't support the post of the new element.

The fix is to modified DrupalWebTestCase and add the email type.

Patch coming up. Plus this needs a re-rolled.

ericduran’s picture

Actually lets wait till the #1174640: Add new HTML5 FAPI element: number element gets in so we don't have to re-roll it again.

Dave Reid’s picture

email element is supported in the 6.x-2.x of SimpleTest which is used by PIFR: #1177106: False install failure when testing HTML5 email element patch

ericduran’s picture

@quicksketch and anyone else interested in D7 support I added a patch to the contrib simpletest module #1415926: Simpletest doesn't allow the new html5 elements to be submitted properly. to add the new form elements.

ericduran’s picture

Ha sorry for the x-post, I completely missed that.

Jacine’s picture

Issue tags: +sprint

Adding this to the current HTML5 sprint.

Niklas Fiekas’s picture

Status: Needs work » Needs review
FileSize
2.63 KB
14.98 KB

There were a few merge conflicts when rebasing onto 8.x, so here is a reroll.

Look at the interdiff for these new things:

  • trim() addresses, because that might be common sense, but also because the contact form tests explicitly have test for e-mail adresses padded with whitespace.
  • Fix an assertion that was failing due to a string change.
  • Remove the test method UserValidationTestCase::testMailAddresses(), because the function user_validate_mail() that is tested there was removed.
Niklas Fiekas’s picture

Added tests.

ericduran’s picture

Status: Needs review » Needs work

Nice. Here's what's missing on this patch.

+++ b/core/includes/form.incundefined
@@ -3703,8 +3703,48 @@ function theme_textfield($variables) {
+  _form_set_class($element, array('form-text', 'form-email'));

We are no longer doing both classes. We now only do the class element. So it should only be _form_set_class($element, array('form-email')); and the css for that new element should be added :)

Also I hate to nitpick this patch. But should we really have the trim? I think this is a bad idea. If I enter " myemaiL@aol.com" that should be invalid. Same goes for any other whitespace. We shouldn't be trying to correct a user mistake. Even worse I would hate to have to always use trim because we are allowing spaces to be allowed in the 'email' field.

Besides that the patch looks great :)

ericduran’s picture

Oh actually I realized something else. We no longer require this change.

+++ b/core/includes/form.incundefined
@@ -3703,8 +3703,48 @@ function theme_textfield($variables) {
+/**
+ * Return the autocompletion HTML for a form element.
+ *
+ * @param $element
+ *   The renderable element to process for autocompletion.
+ *
+ * @return
+ *   The rendered autocompletion element HTML, or an empty string if the field
+ *   has no autocompletion enabled.
+ */
+function form_add_autocomplete(&$element) {
   $extra = '';
-  if ($element['#autocomplete_path'] && drupal_valid_path($element['#autocomplete_path'])) {
+
+  if (!empty($element['#autocomplete_path']) && drupal_valid_path($element['#autocomplete_path'])) {
     drupal_add_library('system', 'drupal.autocomplete');
     $element['#attributes']['class'][] = 'form-autocomplete';
 
@@ -3717,9 +3757,21 @@ function theme_textfield($variables) {

@@ -3717,9 +3757,21 @@ function theme_textfield($variables) {
     $extra = '<input' . drupal_attributes($attributes) . ' />';
   }
 
-  $output = '<input' . drupal_attributes($element['#attributes']) . ' />';
+  return $extra;
+}
 

Instead it should be done inside the theme_email field. I know it sucks, but the refactoring for the autocomplete is happening on a separate issue (#1309394: Process #autocomplete_path for all form elements; remove custom/duplicated code from theme_textfield()

Niklas Fiekas’s picture

Thanks for reviewing.

Even worse I would hate to have to always use trim because we are allowing spaces to be allowed in the 'email' field.

You wouldn't have to, because the value will be trimmed. But anyway, yeah, we probably shouldn't do that. Would we update the contact form tests accordingly, so that they don't expect whitespace-padded e-mail addresses to work?

ericduran’s picture

Ahh, I see you're setting the value back with the trim. I completely miss that. You can feel free to ignore my trim comment ;-)

Niklas Fiekas’s picture

Status: Needs work » Needs review
FileSize
2.61 KB
19.46 KB

Ok, did these things.

Ahh, I see you're setting the value back with the trim. I completely miss that. You can feel free to ignore my trim comment ;-)

Yeah ... but it might still be a valid point. Browsers wouldn't even let through foo@foo.com. So maybe, maybe it's cleaner to adjust the contact form test cases and don't trim anything. Edit: I take this back. testRequiredFields() makes similar assumptions, too.

ericduran’s picture

FileSize
18.61 KB

The previous patch looks great. Here's an update with a couple of fixes.

Fixes are:
- Fix the '$element['#attributes']['type'] = 'tel';' and changed it to email.
- Remove the form_add_autocomplete function as that's being handle in a different issue.
- Remove the trim, because we always said we'll follow what the browsers do. I tested this and if you add spaces the broswer won't let you submit. So we shouldn't do it differently.

Thats all the changes. :)

Status: Needs review » Needs work

The last submitted patch, 1174620-html5-email-45.patch, failed testing.

Niklas Fiekas’s picture

Status: Needs work » Needs review
FileSize
598 bytes
18.64 KB

Thanks.

Fix the '$element['#attributes']['type'] = 'tel';' and changed it to email.

This one is funny, having that I didn't even copy&paste it from tel, but that I was typing it while having the tel element on the right :)

Changes:

  • Only try to validate if not empty.

However we are still expecting test failures due to the now different error messages. This brings me to a point: The error message is currently like that: The e-mail address <em> nfoKbDWr@example.com</em> is not valid.. But this is what the user sees then: The e-mail address nfoKbDWr@example.com is not valid (the whitespace isn't visible). So ... what are we going to do about that?

Status: Needs review » Needs work

The last submitted patch, 1174620-html5-email-47.patch, failed testing.

Dave Reid’s picture

Let's just trim the form value like with url. It doesn't make sense to have spaces before or after an e-mail address, so let's just make the element more usable and trim it.

ericduran’s picture

Yea, I guess the trim can only help. Fine by me.

Niklas Fiekas’s picture

Status: Needs work » Needs review
FileSize
1.86 KB
19.09 KB

Ok, thanks. Added back trim.

ericduran’s picture

Status: Needs review » Reviewed & tested by the community

This one is also RTBC.

Notes on the RTBC Status:
- This patch does exactly what we agree to do with all the elements for now.
- Follows the same pattern as the other new element aka "tel" element

This should be good to go :)

Dave Reid’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/contact/contact.testundefined
@@ -126,7 +126,7 @@ class ContactSitewideTestCase extends DrupalWebTestCase {
-    $this->assertText(t('You must enter a valid e-mail address.'), t('Valid e-mail required.'));
+    $this->assertRaw(t('The e-mail address %mail is not valid.', array('%mail' => 'invalid')), 'Valid e-mail required.');

Should probably be just $this->assertText(t('The e-mail address invalid is not valid.'), 'Valid e-mail required.')); for consistency with the other assertions like with the url element.

+++ b/core/modules/system/system.moduleundefined
@@ -374,6 +374,16 @@ function system_element_info() {
+    '#maxlength' => 128,

Should we consider making the default maxlength for e-mail fields the constant EMAIL_MAX_LENGTH instead? I think we have way more uses of 254/255 characters than 128 which could help simplify some FAPI code.

Marking only back to needs review.

Niklas Fiekas’s picture

Oh ... yes, EMAIL_MAX_LENGTH as the #maxlength should be fine.

About the first point: Yes, I actually thought about that. I think it should be like that, because t('The e-mail address invalid is not valid.') would be a new localizable string, and such strings shouldn't be introduced in test cases. Only t()-strings that are already defined in other places should/must be used.

Dave Reid’s picture

Status: Needs review » Needs work
+++ b/core/includes/install.core.incundefined
@@ -1746,7 +1746,8 @@ function _install_configure_form($form, &$form_state, &$install_state) {
     '#maxlength' => EMAIL_MAX_LENGTH,

We can remove this now.

+++ b/core/modules/contact/contact.pages.incundefined
@@ -73,7 +73,7 @@ function contact_site_form($form, &$form_state) {
     '#maxlength' => 255,

And this one.

+++ b/core/modules/contact/contact.pages.incundefined
@@ -215,7 +212,7 @@ function contact_personal_form($form, &$form_state, $recipient) {
     '#maxlength' => 255,

And this one. :)

+++ b/core/modules/user/user.moduleundefined
@@ -963,7 +938,7 @@ function user_account_form(&$form, &$form_state) {
     '#maxlength' => EMAIL_MAX_LENGTH,

And this one too. :)

Niklas Fiekas’s picture

Right, thanks :) Ignore this one.

Niklas Fiekas’s picture

Status: Needs work » Needs review
FileSize
1.97 KB
19.28 KB

Oh ... that was #54 again. Now what was meanted to be #56.

aspilicious’s picture

Status: Needs review » Needs work
+++ b/core/modules/user/user.moduleundefined
@@ -1149,20 +1123,15 @@ function user_account_form_validate($form, &$form_state) {
   // Trim whitespace from mail, to prevent confusing 'e-mail not valid'
   // warnings often caused by cutting and pasting.

This comment is not needed anymore.

Besides of that ==> RTBC

Niklas Fiekas’s picture

Status: Needs work » Needs review
FileSize
628 bytes
19.29 KB

Right. Thanks.

aspilicious’s picture

Status: Needs review » Reviewed & tested by the community

Good...

ericduran’s picture

Status: Reviewed & tested by the community » Needs work

Is it me, or is there a test missing.

Right now an invalid email is tested and an email address with spaces around it. We also need to test just a regular email address without spaces around it.

If this is already somewhere I'm sorry and feel free to mark it it RTBC again.

aspilicious’s picture

Hmm yeah you're right... Although you can say it should work because of the valid with spaces...

Niklas Fiekas’s picture

Status: Needs work » Needs review
FileSize
860 bytes
19.63 KB

Ok, added that.

Until now there were only implicit tests through site installation, user registration and contact form.

ericduran’s picture

@Niklas Fiekas you're awesome :)

We'll wait for the test bot. But this looks good.

aspilicious’s picture

Status: Needs review » Reviewed & tested by the community

Should be rly rtbc now...

catch’s picture

Status: Reviewed & tested by the community » Fixed

I've marked #1309394: Process #autocomplete_path for all form elements; remove custom/duplicated code from theme_textfield() back to needs review, it'd be really good tg get that one in so as not have to keep duplicating that theme function autocomplete stuff all the time.

Committed/pushed to 8.x. Thanks!

ericduran’s picture

Status: Fixed » Reviewed & tested by the community

@catch it looks like this commit didn't actually make it up to drupal.org. Same thing with a couple of other issues.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Tried again :)

sun’s picture

Awesome! Great work, guys! :)

Somehow wasn't subscribed to this yet. Perhaps I'm also missing other issues.

Would be cool if anyone of you could remind us of new form elements with autocomplete support landing in core over in #1309394: Process #autocomplete_path for all form elements; remove custom/duplicated code from theme_textfield(), as long as that didn't land yet. :)

Dave Reid’s picture

Note I added 'email' to the change notification at http://drupal.org/node/1315186

Niklas Fiekas’s picture

Status: Fixed » Needs review
FileSize
2.39 KB

Looks like we forgot to add testcoverage for disabled email elements and email elements with placeholders. Reopening to add this. (Untested patch attached.)

Status: Needs review » Needs work

The last submitted patch, 1174620-html5-email-fixup-testcoverage-71.patch, failed testing.

aspilicious’s picture

+++ b/core/modules/simpletest/tests/form.testundefined
@@ -261,7 +261,7 @@ class FormsTestCase extends DrupalWebTestCase {
+    $this->assertEqual(count($disabled_elements), 36, 'The correct elements have the disabled property in the HTML code.');

Should be 35?

Niklas Fiekas’s picture

Status: Needs work » Needs review
FileSize
773 bytes
2.39 KB

Oh, indeed. Typo there.

aspilicious’s picture

Status: Needs review » Reviewed & tested by the community

back to rtbc

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed the missing tests to 8.x.

Jacine’s picture

Title: Add new HTML5 FAPI element: email » Change notice: Add new HTML5 FAPI element: email
Status: Fixed » Active
Issue tags: +Needs change record

Sweet! Thanks everyone :D

I assume this needs a change notice?

Dave Reid’s picture

Title: Change notice: Add new HTML5 FAPI element: email » Add new HTML5 FAPI element: email
Status: Active » Fixed
Issue tags: -Needs change record

See #70.

Jacine’s picture

Issue tags: -sprint

Thanks @davereid :D

Removing the sprint tag.

Automatically closed -- issue fixed for 2 weeks with no activity.