Example 6

Build filter form by code

This example highlights the code required to make and manage the filter form by code and not by parameters (since CYap 2.1.0).

First, I create the CYAP object as usual.

<?php
$p=new CYap(array(), array(), $db_info$Show_info, array());

Then I get the reference to the form object.

// Get the filter object
$FilterObj=$p->GetSearchObject();

First statement, I want the field disposed on two columns. If I don't set anythink the default one column will be used.

// Form Layout: 2 column layout
$FilterObj->SetLayoutClass('CYAP_cls2ColumnLayout');

Now it's time to add our first text box. And configure it

// Add range of text input object;
// Create the field. The index are the same as $SearchFieldCfg
$f1=new CYap_clsSearchRangeTxt(array(
                             
// Textbox label
                            
'description' => 'Event Date',
                            
// DataBase field where look for the typed string
                            
'fieldname'   => 'DEvent',
                            
// A=alphabetic, N=Numeric
                            
'type'        => 'A',
                            
// Field size. Used to set the textbox size
                            
'size'        => 14,
                            
/* use regex to match the field
                             * contents against the requested
                             * string. 1=yes, 0=no */
                            
'useregex'   => ),'TxtRange');
// Add the field to the filter form
$FilterObj->AddSearchField($f1,'TxtRange');

The second input text.


// Second input. You may setup the parameters later
$f2=new CYap_clsSearchRegexOpt(array(),'TxtRegex');
// Parameters setup. You may set one paramneter on each call..
$f2->LoadCFg(array('description' => 'Event Date'));
// ... or many paramters with one call
$f2->LoadCFg(array('fieldname'   => 'DEvent',
                  
// A=alphabetic, N=Numeric
                  
'type'        => 'A',
                  
'size'        => 14,
                  
'useregex'   => ));
// Add the field to the filter form
$FilterObj->AddSearchField($f2,'TxtRegex');

Third and last input box.


//third... select input type
$f3=new CYap_clsSearchSelectBox(array( // Label
                                      
'description' => 'Error Code',
                                       
// DataBase field where look for the typed string
                                      
'fieldname'   => 'errno',
                                      
// A=alphabetic, N=Numeric
                                      
'type'        => 'N'),'SelectBox');
// Now add the available options to choose from
$f3->AddOption'OK (0)','0');
$f3->AddOption'Err 512','512');
$f3->AddOption'Err 1024','1024');
// ALL rows option
$f3->AddOption'No selection','NOFILTER');
// Add the field to the filter form
$FilterObj->AddSearchField($f3,'SelectBox');

Finally show the result.


// Finally show the table
$p->showpage();
echo 
'</body></html>';
?>

Click here to download the complete example.