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; $msg =''; if(isset($args['btnAddEdit'])&&('Edit Entry!'==$args['btnAddEdit'])) { $gpb_fields = array('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_UPDATE,'gpb_id = '.$args['gpb_id']); $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 //{{{ do some basic validation on the posted id $gpb_id=$_POST['gpb_id']; $tpl->assign('gpb_id',$gpb_id); $tpl->assign('edit','true'); //}}} //{{{ retrieve details from db $query = "SELECT * FROM `global_phone_book` WHERE `gpb_id` = $gpb_id"; $res = $db->query($query); if(handleError($res)) { $found = array(); $res->fetchInto($row); } //}}} //{{{ 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','Edit Entry!'); $defaults=array('txtName'=>$row['gpb_name'], 'txtNumber'=>$row['gpb_number']); $typeSel->setSelected($row['gpb_type']); $form->setDefaults($defaults); //}}} $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); //}}} ?>