back when we first put the form API in, we talked about expanding the kinds of element types that would be available in core.

attached patch adds one, '#type' => 'email'. has email validation built in.

i think email form elements are common enough to warrant this being in core, and it's a pretty minor code addition.

CommentFileSizeAuthor
#3 email_element_0.patch7.22 KBhunmonk
email_element.patch1.65 KBhunmonk

Comments

moshe weitzman’s picture

good idea ... lets actually use the element in admin site settings, registration, profile edit, ...

dries’s picture

Great idea and but as Moshe said: let's use it in core wherever we can. :)

(Also, we write 'mail' instead of 'email' elsewhere.)

hunmonk’s picture

StatusFileSize
new7.22 KB

okay, as requested, i've used the form element in all appropriate core places i could think of. i was hesitant to use it for user email validation, as it looked to me like the user module validation API stuff could be called programmatically as well. if we decide that it's safe to use there, it would be trivial to add.

also ran some tests on it at the site config page, and it works as advertized. note that there are some variable warnings on that page, but further investigation revealed that they were there before this patch as well, so they should be cleaned up in another patch i think...

Stefan Nagtegaal’s picture

Ehm, can we add some jQuery goodness so the new mail formitem get's automagically validated when the user tabs/leaves the field?

A nice green mark when it's okay, and error messages in red when it's not?

hunmonk’s picture

@Stefan Nagtegaal: not that i disagree with with the usefullness of your request, but that is major scope creep for this patch... :)

eaton’s picture

There are a couple of notices that are thrown on comment preview, but they appear to occur even without the patch. Looks like it works, and could make things simpler for people wanting to collect email addresses.

I'm a bit concerned about the possible element namespace explosion if we begin making custom element types for what are, essentially, distinct validations of generic text fields, but email addresses may be common enough to merit a special case.

hunmonk’s picture

Assigned: hunmonk » Unassigned

i still think this is a good idea, but i'm not going to carry the ball on it anymore...

catch’s picture

Version: 6.x-dev » 7.x-dev
Status: Needs review » Needs work

No longer applies, moving to D7.

TapocoL’s picture

An idea I get from this is to give an option of a duplicate text field that is checked to match the first field. Here is an example:

$form['email'] = array(
  '#type' => 'email',
  '#confirmation' => TRUE,
);

will output two text fields for Email Validated fields with the second field only being used as a confirmation that it matches the first one. I see the double-entry emails on many sites, and figure that it could have it's place here as well.

drewish’s picture

subscribing...

robloach’s picture

Title: add 'email' form element » Add 'mail' form element

Just a quick note that I think this is a good idea. Would be good to consider multiple email addresses too (like in the contact module's recipients).

Jaza’s picture

Version: 7.x-dev » 8.x-dev

Moving.

valthebald’s picture

I think this should be closed as a duplicate of (fixed) #1174620: Add new HTML5 FAPI element: email

yoroy’s picture

Status: Needs work » Closed (duplicate)

Great, lets do that :)