8/12/2019 CRUD Module Development
1/15
Drupal Module
Development
8/12/2019 CRUD Module Development
2/15
Creating Forms in Drupal
The primary method of submitting contentover the Web is through HTML forms.
While the ubiquity of forms makes life easy
for the web user, the dearth of good forms
processing tools usually makes form
development a joyless chore for
programmers. However, forms processing
is one area in which Drupal excels
8/12/2019 CRUD Module Development
3/15
Creating Forms in Drupal
The Forms API (FAPI) provides aprogramming interface that takes the pain
out of form development (or at least
significantly reduces the pain). Using the
FAPI, developers can provide a single
form definition and let Drupal build and
display the form, collect the results, and
even validate and escape form data.
8/12/2019 CRUD Module Development
4/15
Handling Forms with the Forms API (FAPI)
Perhaps the most common but timeconsuming aspect of web development is
form handling. Typically, a form must be
defined and prepared for display. Then,
when form data is submitted to the server,
various form processing tasks must be
conducted to validate, manipulate, and
store form data. Drupal has a special APIfor handling data.
8/12/2019 CRUD Module Development
5/15
Handling Forms with the Forms API(FAPI)
Forms API (FAPI). FAPI automaticallyhandles the mundane details of form
handling, making it much easier for
developers to quickly write forms.
Using the Forms API, developers can
create a single form definition that is then
used by Drupal to perform various aspects
of form handling. The same data structure
that is used to generate the form is also
used to validate the form.
8/12/2019 CRUD Module Development
6/15
And with a few simple functions, complexforms can be handled effectively. FAPI
stands out as one of the gems in Drupal's
crown because of these features.
While we will return to some aspects of the
API later in the book, if you are looking for
an in-depth discussion beyond what this
chapter has to offer, the Drupal website
has some very good articles.
8/12/2019 CRUD Module Development
7/15
:The "quickstart" guide to the Forms API:
http://api.drupal.org/api/ file/developer/topics/forms_api.html/6
The Forms API Quick Reference:
http://api.drupal.org/api/file/ developer/topics/forms_api_reference.html/6
Form API changes between Drupal 5 and Drupal 6:http://drupal.org/ node/144132
The Form Generation API overview:http://api.drupal.org/api/group/ form_api/6
8/12/2019 CRUD Module Development
8/15
Sample Code
8/12/2019 CRUD Module Development
9/15
Sample Code
In its simplest form, the drupal_get_form() function takes a callback function
and uses the results of that function to create a form structure and thenmanage handling of the resulting form. In the above example, it will return an
HTMrmatted form. While the drupal_get_form() function only makes use of one
argumentthe name of the callback functionit can take more arguments. Any
additional arguments will simply be passed on to the functions that it calls
8/12/2019 CRUD Module Development
10/15
Activity 1- Create Entry Form
8/12/2019 CRUD Module Development
11/15
8/12/2019 CRUD Module Development
12/15
Cont.
Objective is to:Add fields for School Year,Semester,Major,
Year Level and College
Add student record in the database.
8/12/2019 CRUD Module Development
13/15
Activity 2-Create Search Form
Objective is to : Create a form that allows user to filter
students per school year and sem
Add additional filter by:
Gender
Student Major
Year Level
8/12/2019 CRUD Module Development
14/15
Activity 3-Edit Form
Objective is to:
Create Edit Form for student record.
Allows user to change the student
information.
8/12/2019 CRUD Module Development
15/15
Drupal Module
Development
ICT CenterWe are making IT happen
IC
T
Integrity
Commitment
Teamwork