I tried implementing the email field using:
$form['personalinfo']['email'] = array(
'#type' => 'email',
'#title' => t('Email'),
'#required' => TRUE,
'#default_value' => "",
'#description' => "Please enter your email.",
'#size' => 20,
'#maxlength' => 20,
);
However, nothing gets rendered. Could you provide some docs and examples on usage?
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | 970068-21.patch | 3.01 KB | chrisrockwell |
| #16 | email_form_type-970068-16.patch | 2.85 KB | tomogden |
| #9 | 970068-9.patch | 1.89 KB | jeroent |
Comments
Comment #1
Nephele commentedI'm guessing that the main problem here is a bug in the alpha2 code -- see #949970: No default/plain formatter, Email contact form doesn't work. Patching the code should make it possible to get something to render (at least with the default and plain formatting options).
Comment #2
les limYou can't use fields like that with Form API. The "#type" property refers to an element type, not a field type, and this module does not define any new element types (it makes use of the existing textfield element type).
Comment #3
kenorb commentedSo the question is: What's the correct example to use Email field programatically?
Regarding element type:
http://api.drupal.org/api/drupal/modules%21system%21system.api.php/funct...
http://nodesforbreakfast.com/article/2012/02/24/create-custom-form-api-e...
Comment #4
kenorb commentedComment #5
les limI suppose that depends: what is the use case for implementing Email Field programmatically? If it's just to implement a Form API textfield that validates email addresses, that can be done without the module:
I'm not sure it's in the scope of this module to do the above, but a maintainer might disagree.
Comment #6
kenorb commentedOr we could add the element_info():
Comment #7
chop commentedI'm with you kenorb, why don't we add an email field type? How about you roll up a patch and let's see if we can't get this sucker into the core form API. It seems as elementary as having a password field type.
Comment #8
Albert.Liu commentedMaybe you can refer to drupal core system contact module snippets below:
Comment #9
jeroentAs suggested by kenorb, I added an emailfield using hook_element_info + some extra changes.
Patch attached.
Comment #10
DrCord commentedThis patch seems to work great! Thanks. This should certainly be included in this module if not in core forms.
Comment #11
DrCord commentedComment #12
tomogden commented#9 patch passes my tests. It solves some very basic needs in a way that is simpler and more future-proof than anything else.
Comment #13
tomogden commentedComment #14
tomogden commentedIt seems the patch at #9 has an odd line count error which prevents it from being applied automatically. I have rerolled it and fixed a couple of minor format items.
Comment #15
tomogden commentedComment #16
tomogden commentedOne more time.
Comment #17
bceyssensSeems to work for me
Comment #18
nikita petrov commentedWhy this functionality is still not in the release? Many people needs this functionality, why they should apply some patches in almost a year?
Comment #19
weri commentedNeeded functionality for this type of field. Patch #16 works as expected.
Hope this gets added in the next release.
Comment #20
rcodinaWorks for me too. This is clearly RTBTC, why it isn't committed yet?
Comment #21
chrisrockwell commentedShould this be updated to add a widget type "Email", similar to what d8 has done (https://www.drupal.org/files/drupal8.email-field.29.patch)? For backwards compatibility the textfield type would have to be allowed as well.
Comment #22
nickbits commentedCan confirm patch #16 works for me.
Comment #23
hugronaphor commentedIs the maintainer of this module alive? Can we move it forward?
Comment #24
fool2 commented+1 for this patch, still works!