« Sarmatian Connection | Main | Using JavaScript Validation For Mandatory Form Elements »

April 14, 2009

Populating Select Element Option Lists with option_switcher.php

<select/> form elements that are included with a select or select_noadd directive in a .skini need to be populated with options.

This is achieved via the common_php/option_switcher.php script and the options_switcher() function.

    switch($form){
        
        case 'room_details':

        switch($label){
    
            case 'Location': return get_options(just_sql("select ID as location_id, name from location order by name"), "location_id", "name");
            case 'Bookable?' : return '<option value="1"/> Yes'."\n".'<option value="-1"/> Staff Only';
            case 'Equipment': return get_options(just_sql("select * from equipment where expired_date is null order by name"), "equipment_id", "name");
            case 'Remove from view?' : return '<option value="'.mktime().'" style="color: red;"/> Yes'."\n".'<option value="nulled"/> No';
            
            }
            
        case 'booking_details':

        switch($label){
    
            case 'Start Time': return get_start_times($day);
            
            case 'Duration': return get_durations();
            
            case 'Your email address' : return '<option value="@cumbria.ac.uk" selected="true"/> @cumbria.ac.uk';
            
            }
...........................
    }

You will need to add a case with your .skini file name stump and then a switch / case block for each of the select form elements in the form. These are designated by the label you gave them in the .skini file.

Most of the examples you will come across make use of the get_options(just_sql("select * from blah"), $value, $label) function. This takes a just_sql() function call reply and an argument for the column names in the results which go to populate the option value and label respectively.

Tags: Lightweight PHP Web Application Framework

Posted by pj at April 14, 2009 11:53 AM

Comments