Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Hi,

How do I implement audit trail using cwp (PHP)?

That's a bit of a broad question really where the answer is simple, but maybe not if you're not sure what you're doing...

1) User "Saves" data

2) This data is POSTed to your submission page - not the database

3) You should have posted a record ID with the rest of your data

4) Send a request to fm for the current record details i.e.

$record = $fm->getRecordById('layout',$_POST[recid])

5) Compare your fields in the current record to those the user just submitted:


$rec = $fm->getRecordById('layout',$_POST[recid]);



if ( $rec->getField('myField') <> $_POST['myField'] ) {

$audit[myField][prev] = $rec->getField('myField'); 

$audit[myField][new] = $_POST['myField'];

}



... or better yet, just stick a function at the top of your page:



function audit_check($fieldName,$record,&$audit){

   if( $record->getField($fieldName) <> $_POST[$fieldName]) 

   $audit[$fieldName] = array("prev"=>$record->getField($fieldName),"new"=>$_POST[$fieldName]);

}



$record = $fm->getRecordById('layout',$_POST[recid]);



audit_check('field_1',$record,$audit_array);

audit_check('field_2',$record,$audit_array);

audit_check('field_3',$record,$audit_array);

audit_check('field_4',$record,$audit_array);

if( count($audit) > 0 ) {

	foreach( $audit_array as $fieldName=>$entry ) {

                $entry['fieldName'] = $fieldName;

		$entry['parent_id'] = $record->getField('pk'); /*This should be your PK field*/

		$add = $fm->newAddCommand('auditLayout',$entry) /*assumes you have four fields called "prev", "new", "fieldName" and "parent_id" on a layout called "auditLayout", you could also do this to a portal attached to the main record - would probably also be quicker, but for the sake of simplicity....*/

		$res = $add->execute();

		/*Might want to trap for an error here*/

	}

}

You would then proceed to actually post the changes to your database... But to re-iterate this is the idea:

1) Database has data

2) User sends data to php - not to database

3) You can retrieve the current record values and compare to user submitted values - save in temporary array

4) Save records to database

5) Submit Audit to wherever you are storing it in the db.

Feel free to ask if you want clarification

  • Author

Thats a good Idea. I will try this B)

1. $myAudit = contains all changes

2. submit actual data

3. create new record in audit table with $myAudit details.

Thank you

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.