Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Apress.Pro.Drupal.7.Development.3rd.Edition.Dec.2010.pdf
Скачиваний:
74
Добавлен:
14.03.2016
Размер:
13 Мб
Скачать
☆

CHAPTER 11 ■ THE FORM API

Additional resources

•The Examples module (http://drupal.org/project/examples) provides more examples, including an AJAX-enabled dependent dropdown, and several other examples, including an example of graceful degradation when Javascript is not enabled.

•See the AJAX Framework (http://api.drupal.org/api/group/ajax/7) documentation and the Form API Reference

Summary

After reading this chapter, you should understand the following concepts:

•How the form API works.

•Creating simple forms.

•Changing the rendered form using theme functions.

•Writing a validation function for a form or for individual elements.

•Writing a submit function and doing redirection after form processing.

•Altering existing forms.

•Creating dynamic forms.

•Using the #ajax property to create dynamic forms that react to users input without page reloads

•The form definition properties you can use and what they mean.

•The form elements (text fields, select fields, radios, and so on) thatre available in Drupal.

•How AJ-based text replacement works with forms.

For more information about forms, including tips and tricks, see the Drupal Handbook at http://drupal.org/node/37775.

293

C H A P T E R 1 2

■ ■ ■

Manipulating User Input:

The Filter System

Adding content to a web site can be quite a chore when you have to format the information by hand. Conversely, making textual content look good on a web site requires knowledge of HTML—knowledge most users don’t want to be bothered with. For those of us who are HTML-savvy, it’s still a pain to stop and insert tags into our posts during the middle of a brainstorm or literary breakthrough. Paragraph tags, link tags, break tags . . . yuck. The good news is that Drupal uses prebuilt routines called filters to make data entry easy and efficient. Filters perform text manipulations such as making URLs clickable, converting line breaks to <p> and <br /> tags, and even stripping out malicious HTML. hook_filter_info() is the mechanism behind filter creation and manipulation of user-submitted data.

Filters

Filters are almost always a single action such as “strip out all hyperlinks,” “add a random image to this post,” or even “translate this into pirate-speak” (see pirate.module at http://drupal.org/project/ pirate). As shown in Figure 12-1, they take some kind of textual input, manipulate it, and return output.

Figure 12-1. A filter transforms text in some way and returns the transformed text.

295

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]