See the documentation at http://platon.sk/projects/doc.php/phpMyEdit/html/configuration.triggers.html Also, use the Forum's search feature to look for "trigger" or "triggers" http://platon.sk/forum/projects/?c=5 Trigger Documentation: http://platon.sk/projects/doc.php/phpMyEdit/html/configuration.triggers.html Select triggers - View form is related to 'select' operation. $opts['triggers']['select']['cancel'] = 'mfg-resources/triggers/categories.TSC.inc'; // After canceling the view page $opts['triggers']['select']['pre'] = 'mfg-resources/triggers/categories.TSP.inc'; // Before displaying the view page Insert triggers - Add and Copy forms are related to 'insert' operation $opts['triggers']['insert']['after'] = 'mfg-resources/triggers/categories.TIA.inc'; // After requesting save or more in the add/copy page $opts['triggers']['insert']['before'] = 'mfg-resources/triggers/categories.TIB.inc'; // Before requesting save or more in the add/copy page $opts['triggers']['insert']['cancel'] = 'mfg-resources/triggers/categories.TIC.inc'; // After canceling the add/copy page $opts['triggers']['insert']['pre'] = 'mfg-resources/triggers/categories.TIP.inc'; // Before displaying the add/copy page Update triggers - Edit form is related to 'update' operation. $opts['triggers']['update']['after'] = 'mfg-resources/triggers/categories.TUA.inc'; // After requesting save or apply in the edit page $opts['triggers']['update']['before'] = 'mfg-resources/triggers/categories.TUB.inc'; // Before requesting save or apply in the edit page $opts['triggers']['update']['cancel'] = 'mfg-resources/triggers/categories.TUC.inc'; // After canceling the edit page $opts['triggers']['update']['pre'] = 'mfg-resources/triggers/categories.TUP.inc'; // Before displaying the edit page Delete triggers - Delete form is related to 'delete' operation. $opts['triggers']['delete']['after'] = 'mfg-resources/triggers/categories.TDA.inc'; // After requesting delete in the delete page $opts['triggers']['delete']['before'] = 'mfg-resources/triggers/categories.TDB.inc'; // Before requesting delete in the delete page $opts['triggers']['delete']['cancel'] = 'mfg-resources/triggers/categories.TDC.inc'; // After canceling the delete page $opts['triggers']['delete']['pre'] = 'mfg-resources/triggers/categories.TDP.inc'; // Before displaying the delete page --------------------------------------------------------------------- Variables available within included triggers: $this object reference $this->dbh initialized MySQL database handle $this->key primary key name $this->key_type primary key type $this->key_delim primary key deliminator $this->rec primary key value (update and delete only) $newvals associative array of new values (update and insert only) $oldvals associative array of old values (update and delete only) $changed array of keys with changed values --------------------------------------------------------------------- Trigger example - conditionally populate values in other fields in the same table (an Address Book). If the field "email1" is not empty, populate "display_name" and "nick_name" fields using values found in either "first_name" and "last_name" or (if empty) then "company". if( !empty($newvals['email1']) ) { if( !empty($newvals['first_name']) ) { $newvals['display_name'] = ucwords( $newvals['first_name'].' '.$newvals['last_name'] ); $newvals['nick_name'] = ucwords( $newvals['first_name'].' '.$newvals['last_name'] ); } else if ( !empty($newvals['company']) ) { $newvals['display_name'] = ucwords($newvals['company']); $newvals['nick_name'] = ucwords($newvals['company']); } } --------------------------------------------------------------------- // Trigger file name: mark_as_deleted.TDB.inc // echo "\n".'

Script executed: '.__FILE__.'

'; // test that a field named `deleted` exists in the table // and change the value of `deleted` from 0 to 1 if(isset($oldvals['deleted'])){ $query2 = sprintf('UPDATE %s SET `deleted` = "1" WHERE `%s` = "%s" LIMIT 1', $this->tb, $this->key, $this->rec); if($this->MyQuery($query2)){ // Emulate the change_log function, saving a copy of the record flagged as deleted if($this->logtable){ $query3 = sprintf('INSERT INTO %s (updated, user, host, operation, tab, rowkey, col, oldval, newval) VALUES (NOW(), "%s", "%s", "delete", "%s", "%s", "%s", "%s", "")', $this->logtable, addslashes($this->get_server_var('REMOTE_USER')), addslashes($this->get_server_var('REMOTE_ADDR')), addslashes($this->tb), addslashes($this->rec), addslashes($key), addslashes(serialize($oldvals))); $this->myquery($query3, __LINE__); } return false; }else{ // abort if the query fails echo "\n".'

'.htmlspecialchars(mysql_error()).'

'; echo "\n".'

Go Back

'; exit; } } --------------------------------------------------------------------- // trigger to delete a file if the saved path and filename have been deleted // dir example: /public_html/uploads/images/tn // filename example: foo.jpg if($this->tb == 'my_table' && $_POST['PME_sys_savedelete'] == 'Delete'){ $qry = 'SELECT dir, filename FROM my_table WHERE upload_id = '.$_POST['PME_sys_rec'].' LIMIT 1'; // echo "\n".'

'.htmlentities($qry).'

'; if($row = mysql_fetch_row(mysql_query($qry))){ $tn = $row[0].'/'.$row[1]; // large image was saved with the same filename, 1 directory level above /tn/ $im = str_replace('/tn', '', $tn); if(file_exists($tn)){ unlink($tn); echo "\n".'

Deleting '.$tn.'

'; } if(file_exists($im)){ unlink($im); echo "\n".'

Deleting '.$im.'

'; } } } --------------------------------------------------------------------- foreach($newvals as $key => $val){ if($key == 'some_column_name') { $newvals[$key] = strtoupper($newvals[$val]); } } --------------------------------------------------------------------- Forum post follows Source: http://platon.sk/projects/bug_view_advanced_page.php?f_bug_id=228 /* validating user input with php JavaScript validation is satisfactory in most case. In some cases, it is not reliable or flexible enough. The reasons can be: - no js support in client browser - validadion requires access to database - you don't want users to see what the validation is so you need to use php validation, which is processed on the server. USAGE: 1. place this file as trigger insert before and trigger update before $opts['triggers']['insert']['before'] = 'mfg-resources/triggers/table_validation.php'; $opts['triggers']['update']['before'] = $opts['triggers']['insert']['before']; 2. modify to your needs (within MODIFY tags) TODO: consult js-regexp usage with experts problems with 'help' vs 'help|A' vs 'help|AC' vs ... make bad fields red/bold/whatever (css or hard coded ? ) AUTHOR: michal palenik uploaded to platon.sk on 10 april 2004 */ $errors = false; // default, there is no error /* insert any php code that validates user input the result should be associative array $errors as 'col_name' => 'error message', where col_name is as defined in $opts and 'error message' is anything that you want to display to do user if there is no error, leave $errors at its default value (false) */ // HERE if(strlen($newvals['question']) < 10){ $errors['question'] = "Question must be at least 10 characters long"; } // END // double check for regexp from js validation for ($k = 0; $k < $this->num_fds; $k++) { if (isset($this->fdd[$k]['js']['regexp'])) { $value = $newvals[$this->fds[$k]]; if(!preg_match($this->fdd[$k]['js']['regexp'], $value)){ $errors[$this->fds[$k]] = $this->fdd[$k]['js']['hint']; } } } // if no error, continue if(!$errors) return true; // filling user input in all columns first foreach($newvals as $key => $value){ $this->fdd[$key]['default'] = $value; } // error handling could use a language label for "Problem: echo "\n".'
'; echo "\n".'
    '; foreach($errors as $key => $val) { $this->fdd[$key]['help'] = "\n".'
  1. '.$val.' '.$this->fdd[$key]['help'].'
  2. '; } echo "\n".'
'; echo "\n".'
'; // emulating moreadd/more button $this->operation = $this->labels['Add']; // language unspecific $this->recreate_fdd(); $this->recreate_displayed(); // stopping the insert proccess return false; ------------- Forum Post http://platon.sk/forum/projects/viewtopic.php?p=314883#314883 In a table I have a Column "RowOK". If RowOK is "1" (yes) then I want to set all other fields to "readonly" in this row, when the row is edited (updated). So the record can only be changed after "RowOK" is set back to "0" (No). Solution: pre update trigger $sql = 'SELECT RowOK FROM '.$DB_TABLE.' WHERE ID='.$this->rec; $res = mysql_query($sql) or die(mysql_error()); $record = mysql_fetch_object($res); if($record->RowOK == 1){ $n = sizeof($this->fdn); $x = $this->fdn['RowOK']; for($i=0;$i<$n;$i++){ if($i != $x){ $this->fdd[$i]['input'].="R"; } } } return true; ---------- // A MySQL TEXT column can hold UP TO 65,535 characters. // Test to make sure no more than that are posted. // If necessary, convert the column from TEXT to MEDIUMTEXT // Set 2 lines in the phpMyEdit script: $opts['triggers']['insert']['before'] = 'triggers/check_text_length.php'; $opts['triggers']['update']['before'] = 'triggers/check_text_length.php'; // Code for check_text_length.php follows: $num = strlen($newvals['content']); if($num > 65535){ unset($_POST); abort('Content field length grateer than 65535 = '.number_format($num)); }