Drupal form API provides some built in type of element to build a form. But I want to create other type such as:

$form['mail']['#type'] = 'email';

And the output I want it to be:

<input class="input-1" type="email" id="edit-mail" name="mail" maxlength="128">

So, how can i do that?


You need to implement hook_element_info(). See the form_example_elements.inc file from the Example: Form API module, and the Creating Custom Elements documentation guide.

Note that the Elements module already provides a form element type for HTML5 mail inputs.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy