setTPL("gpb_form.tpl"); $form = new HTML_QuickForm("NewForm"); //}}} /** * Process Data * * This is the callback function to handle the processing of the QF * @author Tristan Coetzee * @param $args Contains the form variables supplied by HTML_QF * @version 0.1.0 */ function process_data($args) { global $db; if('Add Entry!'==$args['btnAddEdit']) { //submit button was pressed $gpb_fields = array('gpb_id','gpb_name','gpb_number','gpb_type'); $gpb_values = array('',$args['txtName'],$args['txtNumber'],$args['selType']); $gpb_query = $db->autoPrepare('global_phone_book',$gpb_fields,DB_AUTOQUERY_INSERT); $gpb_res =& $db->execute($gpb_query,$gpb_values); if(handleError($gpb_res)) { $msg = 'Database Update Successful!'; } else { $msg = 'Warning! Unable to update Database!'; } } return $msg; } //end of process_data callback function //{{{ create object and elements $form->addElement('header',"hdrTop","Edit Phone Book Entry"); $form->addElement('text','txtName','Name: '); $form->addElement('text','txtNumber','Number: '); $types = array('B'=>'Business','P'=>'Private','O'=>'Other'); $typeSel =& $form->addElement('select','selType','Type: ',$types); $form->addElement('submit','btnAddEdit','Add Entry!'); //}}} $form->addRule('numeric','txtNumber','Please enter a valid phone number'); //{{{ create filters $form->applyFilter('all','trim'); //}}} //{{{ create rules $form->addRule('numeric','txtNumber','Please enter a valid phone number'); $form->addRule('required','txtNumber','Please enter a number'); $form->addRule('required','txtName','Please enter a name'); $form->addRule('required','selType','Please select a type'); //}}} //{{{ validate form if($form->validate()) { $result = $form->process('process_data','false'); $form->addElement('text','txtResult',$result); } else { } //}}} //{{{ assign form to tpl and display form $tpl->display(&$form); //}}} ?>