Neatware  Header

    Form

  1. Form

    Form is a window that connects client to a program on the server. Several control components (widgets) such as checkbox help to complete this task. 'action' attribute of the _form command has a URL value that refers to a CGI program. 'method' attribute has one of the value GET, POST, and ENCTYPE. GET method sends the information through env variables; POST method sends the information through stdout; and ENCTYPE method specifies the MIME type for POST data(default 'application/x-www-form-data').

    _html( "xmlns='http://www.w3.org/1999/xhtml' " 
         + "xml:lang='en' lang='en'" );
    _head();
      _title(); quote( "Form" ); title_();
    head_();
    _body();
      _form( "action='/cgi-bin/form.sml' method='POST'" );
      form_();
    body_();
    html_();
    
  2. Button

    • Submit

      'submit' button will send the name=value string to a CGI program. The 'type' attribute of the __input command must be the value 'submit'. The 'value' attribute sets the label of a button (default submit). Finally, 'name' attribute sets the submit name.

      _body();
        _form( "action='/cgi-bin/form.tcl' method='POST'" );
          __input( "type='submit' name='submit_name' " 
                 + "value='button_label'" );
        form_();
      body_();
      
    • Reset

      Reset button clears all the input data. The 'type' attribute of a __input command must be the value 'reset'.

      _body();
        _form( "action='/cgi-bin/form.sml' method='POST'" );
          __input( "type='reset'" );
        form_();
      body_();
      
    • Image

      When user clicks on an image button, browser will send the coordinates of the mouse clicking point to a CGI program. The 'type' attribute of the __input command has the value 'image'; 'src' attribute specifies the file name of the image; and the 'name' attribute is the button id.

      _body();
        _form( "action='/cgi-bin/form.sml' method='POST'" );
          __input( "type='image' src='icon.gif' name='icon'" );
        form_();
      body_();
      
    • Back Button

      With a simple JavaScript statement, you can create a Back button.

      _body();
        _form( "action='/cgi-bin/form.sml' method='POST'" );
          __input("type='button' value='Back' OnClick='history.go(-1)'");
        form_();
      body_();
      
  3. EditBox

    Editbox will open a box with width specified in the 'size' attribute. When 'type' attribute has the value 'text', __input command allows you input text in an editbox. If 'type' has the value 'password', the input characters will be displayed as asterisks. The 'hidden' value of 'type' will hide editbox from display.

    'name' attribute of the __input command specifies the name of an editbox. The 'value' attribute specifies the initial string in the editbox (default 'string'). 'maxlength' attribute specifies the max length of a string.

    _body
      _form "action='/cgi-bin/form.tcl' method='POST'"
        __input "type='text' name='user' size='20' maxlength='50'"
      form_
    body_
    
  4. RadioBox

    Radiobox is a group of circle buttons that only one can be checked. The 'type' attribute in an __input command has the value 'radio'. In a group of radiobox all of them must be the same 'name' attribute. However, they must be different in the 'value' attribute. A CGI program will receive the selected radiobox. 'CHECKED' attribute sets a radiobox as default.

    _body();
      _form( "action='/cgi-bin/form.tcl' method='GET'" );
        quote( "First" );
        __input( "type='radio' name='order' value='first'" );
        quote( "Second" );
        __input( "type='radio' name='order' value='second'" );
      form_();
    body_();
    
  5. CheckBox

    Checkbox is a group of square buttons that can be checked on or off. The 'type' attribute of a __input command has the value 'checkbox'. Each checkbox must have a different 'name' attribute. The checked box will send a value 'on' to a CGI program in default. When the 'value' attribut is defined the name=value will be send. The 'CHECKED' attribute sets a checkbox on as default. You may check more than one box at the same time.

    _body();
      _form( "action='/cgi-bin/form.tcl' method='GET'" );
        __input( "type='checkbox' name='red' CHECKED" );
        __input( "type='checkbox' name='green'" );
        __input( "type='checkbox' name='blue' CHECKED" );
      form_();
    body_();
    
  6. MenuBox

    MenuBox shows a long selectable list in a small space. The 'size' attribute in _select command sets to 1 will make the form work as a menubox. An _option command lists an item. The 'SELECTED' attribute in the _option command selects this item as default.

    _body();
      _form( "action='/cgi-bin/form.tcl' method='GET'" );
        _select( "name='color' size='1'" );
          _option(); quote( "red" );
          _option(); quote( "green" );
          _option("SELECTED"); quote( "blue" );
        select_();
      form_();
    body_();
    
  7. ListBox

    Similar to the MenuBox, however, ListBox must set 'size' a greater than 1 value in the _select command. It is displayed as scrolled list. 'MULTIPLE' attribute in the _select command will allow you select multiple items.

    _body();
      _form( "action='/cgi-bin/form.tcl' method='GET'" );
        _select( "name='color' size='2' MULTIPLE" );
        _option(); quote( "red" );
        _option(); quote( "green" );
        _option( "SELECTED" ); quote( "blue" );
        select_();
      form_();
    body_();
    
  8. EditText

    _textarea command defines a scrolled text editbox with attribute 'rows' and 'cols'. The 'name' attribute specifies the name of a text area. Unlike the HTML text, the text in an EditText area will not ignore newlines.

    _body();
      _form( "action='/cgi-bin/form.tcl' method='GET'" );
        _textarea( "rows='20' cols='40' name='words'" );
        quote( "Demo of Text Editor." );
        textarea_();
      form_();
    html_();
    
  9. CGI and Form

    Client Form is a basic interactive interface connected to a CGI program. Client browser encodes form data by using a MIME type. The default MIME type in the ENCTYPES attribute is application/x-www-form-urlencoded. The value of 'name' attribute attached with '=' and the entered string construct a key/value pair. All the pairs are linked by the '&' character to form a string. CGI encoder will translate control characters into hexadecimal codes with the prefix '%'. For example, the space character is translated to %20.

    For EditBox and EditText in a form if user did not input anything, the value will be left to empty. For RadioBox and CheckBox in a form if a box is checked, the value will be the string in 'value' attribute. Its default value is 'on'. A client will not send a key/value pair if a box is not checked. For MenuBox and ListBox a client will send a key/value pair if user select the item of a _option command.