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 12<br />

Notice that $install_state is passed in as a third variable into the form function.<br />

This is different from typical form functions in the Form API. It provides access to<br />

the state and information in the installer.<br />

Setting the page title<br />

Setting the display_name for a task only sets the title in the list of<br />

installer tasks. To set the page title, use drupal_set_title(). For full<br />

details on using drupal_set_title() see the API documentation at<br />

http://api.drupal.org/api/function/drupal_set_title/7.<br />

Just like other Form API functions we have access to the store_configure_<br />

contact_form_validate() and store_configure_contact_form_submit()<br />

functions, as seen below:<br />

function store_configure_contact_form_validate($form, &$form_state) {<br />

// Validate and each e-mail recipient.<br />

$recipients = explode(',', $form_state['values']['recipients']);<br />

foreach ($recipients as &$recipient) {<br />

$recipient = trim($recipient);<br />

if (!valid_email_address($recipient)) {<br />

form_set_error('recipients', t('%recipient is an invalid e-mail<br />

address.', array('%recipient' => $recipient)));<br />

}<br />

}<br />

form_set_value($form['recipients'], implode(',', $recipients),<br />

$form_state);<br />

}<br />

function store_configure_contact_form_submit($form, &$form_state) {<br />

$values = $form_state['values'];<br />

$values += array(<br />

'cid' => 1,<br />

);<br />

drupal_write_record('contact', $values, array('cid'));<br />

watchdog('contact', 'The default category has been updated.',<br />

array(), WATCHDOG_NOTICE, l(t('Edit'), 'admin/structure/contact/edit/'<br />

. $values['cid']));<br />

}<br />

[ 353 ]

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

Saved successfully!

Ooh no, something went wrong!