Next: , Previous: , Up: Forms Library   [Contents][Index]


4.15.1 The Basics

Forms are created in much the same way as menus. First, the fields related to the form are created with new-field. You can set options for the fields, so that they can be displayed with some fancy attributes, validated before the field looses focus, etc. Then the fields are attached to the form. After this, the form can be posted to display and is ready to receive inputs. Along similar lines to menu-driver, the form is manipulated with form-driver. We can send requests to form-driver to move focus to a certain field, move the cursor to the end of the field, and so on. After the user enters the values in the fields and validation is done, the form can be unposted and the memory allocated can be freed.

The general flow of control of a form program looks like this

  1. Initialize curses
  2. Create fields using new-field. You can specify the height and width of the field, and its position on the form.
  3. Create the forms with new-form by specifying the fields to be attached.
  4. Post the form with form-post and refresh the screen.
  5. Process the user requests with a loop and do necessary updates to the form with form-driver.
  6. Unpost the menu with form-unpost
  7. If desired, explicitly free the memory allocated to menu with free-form.
  8. If desired, explicitly free the memory allocated to menu item with free-field.
  9. End curses.

The forms library is similar to the menu library. The following examples will explore various aspects of form processing. Let’s stat the journey with a simple example first.


Next: , Previous: , Up: Forms Library   [Contents][Index]