Custom CMSB - SAVE and then REDIRECT button

4 posts by 2 authors in: Forums > CMS Builder
Last Post: June 10, 2011   (RSS)

By rjbathgate - June 8, 2011

Hello,

I want to add a new button on the MODIFY page of a record in CMSB, along with the SAVE / CANCEL.

This button is to SAVE the record and then REDIRECT the user to a given URL.

I have got the button made in /lib/menus/edit.php, no problem, but cannot work around the ajax save record function (edit_functions.js)

I have a duplicate custom version of lib/menus/save.php, which is successfully called when the new button is clicked ( /lib/menus/sendToCompany.php)

In sendToCompany.php I have tried using redirectToUrl() but the redirection is made in a Javascript alert popup, resulting in raw code shown in a js alert box, rather than redirecting the main browser window.

My other attempt was to define $returnUrl in sendToCompany.php, however the edit_functions.js does not take this value, rather just the one sent in /lib/menus/edit.php

I'm 85% sure I need to somehow either get the redirectToUrl() working (ignoring the edit_functions.js), or to parse a new $returnUrl to the edit_functions.js, but neither want to work!

Bearing in mind, edit.php needs to still be able to perform all it's usual normal CMSB tasks...

Appreciate this is advanced stuff probably not supported in the forum, but I would be grateful for some pointers!

Cheers
Rob

Re: [rjbathgate] Custom CMSB - SAVE and then REDIRECT button

By Jason - June 9, 2011

Hi Rob,

The easiest thing to do would be to not actually change any of the CMSB code, but to write a plugin that does the redirect. If you use the hook record_postsave, which is executed after the save is completed, you can check for the name of your button in the $_REQUEST array. If it's there, that means your custom button was clicked. You can then use the redirectBrowserToURL(); function to redirect to any URL you want.

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] Custom CMSB - SAVE and then REDIRECT button

By rjbathgate - June 9, 2011

Hi Jason,

Thanks heaps for the reply.

I have achieved it by setting a cookie onclick of the button, and the post save, if the cookie exists, it redirects (and then clears the cookie).

I have done it directly in CMSB code, but I want to/will turn it into a plugin someday!

Thanks