Open Source & stuff 

Salix.gr

User login

sc_form_elements class

Place select boxes, radio groups, checkbox groups on to your page dynamicaly. Items are loaded from database.

In the same file sc_classes.php there is an other class.
Called sc_form_elements. Used partialy from sc_ajax_select_boxes.
It is a nice form helper class. Adds select boxes, radio groups and check box groups.
It is usual to have options on db and have to populate with them select boxes,
or show a list of radio buttons or a list of checkboxes. The routine is to query the
database and loop throu the selected rows and add elements to the form.
sc_form_elements class comes to save time rewriting that peace of code again and again,
but still have control over the form.

Links:

Usage example

$sc_form_elements = new sc_form_elements();
$list = $sc_form_elements->get_list_from_db('sc_page_types','page_type','type_descr','');
$sc_form_elements->add_select_box($list, 'page,page1','t1','id1','',TRUE,5);
 
$sc_form_elements->group_pre_group = '<div>';
$sc_form_elements->group_post_group = '</div>';
$sc_form_elements->add_radio_group($list, 'page','t1',FALSE,'');
 
$sc_form_elements->group_pre_group = '<table>';
$sc_form_elements->group_post_group = '</table>';
$sc_form_elements->group_pre_input = '<td>';
$sc_form_elements->group_post_input = '</td>';
$sc_form_elements->group_wrap_every = count($list);
$sc_form_elements->group_pre_wrap = '<tr>';
$sc_form_elements->group_post_wrap = '</tr>';
$sc_form_elements->add_checkbox_group($list, 'page,page1','t1',FALSE,'');

See demo page.

sc_form_elements reference

Public methods:

  • get_list_from_db
    Syntax: get_list_from_db(db_table_name, key_field_name,
    description_field_name, order_field_name)

    Loads the list of items from database table.
    db_table_name is the database table where select box options are stored.
    key_field_name is the field which holds key values for select box options.
    description_field_name is the field which holds description text for select box options.
    order_field_name is the field you want to be used to order option list. If table is already indexed or you want options shown in the same order that are stored in db set order_field_name value to "".

  • add_select_box
    Syntax: add_select_box(list, selected,
    name, id, extra,
    multiple, size)

  • add_radio_group
    Syntax: add_radio_group(list, selected,
    add_id, extra)
  • add_checkbox_group
    Syntax: add_checkbox_group(list, selected,
    add_id, extra)

Properties:

  • select_prompt_key, select_prompt_text, select_add_prompt_row
    Controls prompt row in select boxes. Prompt row is the row that says "Please select'.

    • select_prompt_key is the value of the option element. Default value is 0.
    • select_prompt_text is the text of the option element. Default value is 'Please Select'.
    • select_add_prompt_row is a boolean that sets the addition of that row. By default is TRUE.
  • group_pre_group, group_post_group, group_pre_input, group_post_input
    Used by grouped elements, radio and check boxes.

    • group_pre_group is the HTML tag that will be placed before the group.
    • group_post_group is the HTML tag that will be placed after the group.
    • group_pre_input is the HTML tag that will be placed before each input element.
    • group_post_group is the HTML tag that will be placed after each input element.
  • group_wrap_every, group_pre_wrap, group_post_wrap
    Used by grouped elements, radio and check boxes. You can set how elements will
    be displayed. To show them verticaly set group_wrap_every=1, to show them in one
    line group_wrap_every=0.

    • group_wrap_every sets how many elements will be shown per row.
    • group_pre_wrap is the HTML tag that will be placed before the row.
    • group_post_wrap is the HTML tag that will be placed after the row.

All Rights Reserved 2006-8 Salix.gr | Hosting by e-emporio