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.

Building an Admin Interface<br />

}<br />

return confirm_form(<br />

$form,<br />

t(<br />

'Are you sure you want to send a warning e-mail to this user?'),<br />

'user/' . $uid,<br />

t('This action can not be undone.'),<br />

t('Send e-mail'),<br />

t('Cancel')<br />

);<br />

The confirm_form() function allows developers to easily create confirmation forms<br />

associated with specific actions. It takes seven arguments, which seems intimidating<br />

but they are actually pretty intuitive.<br />

The first argument contains additional form elements that we want merged into the<br />

resulting confirmation form. As we saw earlier, we have created a value element<br />

containing a user account object. We need this to be passed on to the form's submit<br />

function, so we set it to be added with all the other elements that confirm_form()<br />

creates on its own.<br />

The second argument specifies the question you want to ask when the user is<br />

presented with the confirmation option. This is pretty straightforward and we<br />

have an appropriate message there.<br />

The third argument indicates what URL the user should be sent to if the user cancels<br />

the form. Usually this will be an internal <strong>Drupal</strong> path without leading or trailing<br />

slashes. Typically site administrators will get to this page from a user profile page,<br />

so it is appropriate that when this form is canceled the administrators are returned<br />

to this profile page.<br />

The final three arguments specify various captions used in the form. They are the<br />

additional description text to be displayed above the confirm button, the text of<br />

confirm button, and the text of the cancel link. All of these messages are optional,<br />

and <strong>Drupal</strong> will use sensible defaults if you don't change them here explicitly.<br />

The code above displays the following:<br />

[ 140 ]

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

Saved successfully!

Ooh no, something went wrong!