18.10.2016 Views

Drupal 7 Module Development

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 5<br />

'#size' => 40,<br />

'#maxlength' => 120,<br />

'#required' => TRUE,<br />

);<br />

// Textarea for the body of the e-mail.<br />

$form['user_warn_e-mail_text'] = array(<br />

'#type' => 'textarea',<br />

'#rows' => 10,<br />

'#columns' => 40,<br />

'#title' => t('Warning e-mail text'),<br />

'#required' => TRUE,<br />

'#description' => t('The text of the e-mail which will be sent to<br />

users.'),<br />

);<br />

// Checkbox to indicate if admin should be sent a Bcc on e-mails.<br />

$form['user_warn_bcc'] = array(<br />

'#type' => 'checkbox',<br />

'#title' => t('BCC admin on all e-mails'),<br />

'#description' => t("Indicates whether the admin user (as set in<br />

site configuration) should be sent on all warning e-mails."),<br />

);<br />

// Submit button<br />

$form['submit'] = array(<br />

'#type' => 'submit',<br />

'#value' => t('Save settings'),<br />

);<br />

}<br />

return $form;<br />

The properties of a form element always begin with a # sign in order to<br />

distinguish them from nested form fields. For more information visit the<br />

Form API Quickstart Guide.<br />

This is very similar to what we did earlier while implementing hook_menu(). We<br />

create a specially formatted associative array and return it to the calling function.<br />

In this case, each element in the array corresponds to an element in our form.<br />

Lets look at the subject field first as an example.<br />

$form['user_warn_e-mail_subject'] = array(<br />

[ 129 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!