Execute php code on record save...

10 posts by 3 authors in: Forums > CMS Builder
Last Post: August 16, 2011   (RSS)

By rcrofoot - July 26, 2011

Hello -

I'd like to be able to automatically execute some PHP code when my client clicks "Save" after modifying a record in CMSB...Is there a built-in event handler somewhere that I could insert my code???

Seems like you can do everything else with CMSB, so why not this!

Thanks in advance for the help...

Rick

Re: [rcrofoot] Execute php code on record save...

By robin - July 27, 2011

Hey Rick,

There is a way, but you'll need to use a plugin which is pretty advanced. If you're up to it the hook to use is: record_postsave

This thread has some good ideas on how to get going with that.
http://www.interactivetools.com/forum/gforum.cgi?post=77541#77541

Hope that helps,
Robin
Robin
Programmer
interactivetools.com

Re: [robin] Execute php code on record save...

By rcrofoot - July 27, 2011

Hi Robin -

Thanks for responding...

I'm having a problem accessing the download for the mysql console plugin...My 2 user names & passwords don't work on that screen...

Could you possibly outline what I need to do??? For instance where is [font "Verdana"]record_postsave and is it a built-in event handler...[/#000000]

[font "Verdana"]Also, might there be a more direct way to do this...Can I add another button (or link) on a section editor page that I can access after I save a record???[/#000000]

[font "Verdana"]Just trying to get this done asap...lots of pressure right now...[/#000000]

[font "Verdana"]Thanks, Rick[/#000000]

Re: [rcrofoot] Execute php code on record save...

By Jason - July 27, 2011

Hi Rick,

If you haven't purchased a plugin before, you can sign up for a username/password and you would then have access to the free plugins.

Here is an overview of what you need in a plugin. First, you need a plugin header at the top of the file like this:



You can fill out this information with whatever you want.

After that, you need to add an action on the record_save hook. It would look something like this:

addAction('record_postsave', '_pluginName_myFunctionName', null, 4);

You will change "_pluginName_myFunctionName" with the name of your function. We usually put the name of the plugin in the function name to avoid function name collisions. For example, if you plugin was called duplicateRecords and your function copied a record, you could use a function name like this:
_duplicateRecords_copyRecord

Finally, you need to actually define and code your function. Your function definition would look something like this:

function _pluginName_myFunctionName($tablename,
$isNewRecord, $oldRecord, $recordNum) {

}


You would put the code you want to execute after a record is saved in here. Note that this function will be called after ANY record is saved, so you'll probably want to put in some code that will only execute if the record is in a certain table.

Hope this helps get you started.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Execute php code on record save...

By rcrofoot - July 27, 2011

Thanks Jason...This will help alot...

One last question: Where is the record_save hook...In one of the cmsb php pages???[/#000000]

Thanks, Rick

Re: [rcrofoot] Execute php code on record save...

By Jason - July 27, 2011

Hi Rick,

Yes, the hook inside of the cmsb libraries. All it does is after a record is saved it calls a function that will call any plugin functions using that hook.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Execute php code on record save...

By rcrofoot - July 27, 2011

So as I understand it, I'm really creating a plugin and putting it in the plugins folder...

Then in /usr/www/users/brother/cmsAdmin/lib/menus/save.php, after the line doAction('record_postsave', $tableName, $isNewRecord, $oldRecord, $_REQUEST['num']);, I'll be adding addAction('record_postsave', '_pluginName_myFunctionName', null, 4); using my plugin & function name of course...Sounds interesting...Can't wait to try it...Rick

Re: [rcrofoot] Execute php code on record save...

By Jason - July 27, 2011 - edited: August 8, 2011

Hi Rick,

You shouldn't change anything inside save.php or any of the other cmsb files. All of the code I was showing you just goes in your file that you put in the plugins folder.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Execute php code on record save...

By rcrofoot - August 16, 2011

Hi Jason -

Thanks for the tips re: plugins...

I tried a few weeks ago to implement what I needed but was unsuccessful...I'm going to attempt to write the plugin I need one more time, but because I'm under a heavy workload, I may not have the time to focus...

What would the cost be to have you do it...Is there an hourly rate, or a minimum???...I've written the PHP code...I just need a plugin to execute it when user saves a record in CMSB...



OR, is there a detailed tutorial available, that can walk me thru the process of building it myself...

Thanks for the help...Rick