PHP Redirect on Save

8 posts by 3 authors in: Forums > CMS Builder
Last Post: July 22, 2012   (RSS)

By nmsinc - May 14, 2012

I have a redirect plugin listed below - Is there a way for PHP to redirect to the previous page upon submit rather than a URL?

Thanks - nmsinc

<?php



addFilter('section_init', '_plugin_redirectonsave', null, 2);

function _plugin_redirectonsave($tableName, $action) {
if ($tableName != 'claims_submission') { return; } // only run on accounts tabl
if ($action != 'list') { return; } // only run on list

$recordNum = @$_REQUEST['saved'];
$url = "http://www.claimscaddy.com/claims/listing.php?q=" . urlencode("Saved record $recordNum in $tableName");
redirectBrowserToURL($url);
}

?>
nmsinc

Re: [Jason] PHP Redirect on Save

By nmsinc - May 15, 2012

Hi Jason,

Upon submit, the plugin returns to the listing.php page. Now I have multiple listing pages so I now need the plugin to redirect to the listing page the user came from upon save!

The listing pages for return too are:

listing.php

active_claims_map.php

Thanks - nmsinc
nmsinc

Re: [nmsinc] PHP Redirect on Save

By Jason - May 16, 2012

Hi,

I see, so your users are jumping from a front end list page, to an edit page inside CMS Builder, then redirecting them back to a front end list page.

One thing you can try is, on your list page, set a session variable with the name of the current file they're on.

for example:

<?php
$_SESSION['listPageUrl'] = "http://www.claimscaddy.com/claims/listing.php";
?>


Then in your plugin, you can use the value of $_SESSION['listPageUrl'] as the page your redirect to.

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] PHP Redirect on Save

By nmsinc - May 16, 2012

Your suggestion worked great - thanks Jason!
nmsinc

Re: [nmsinc] PHP Redirect on Save

By usadomains - July 22, 2012

This plugin works great for the users, but how do I get this plugin to ignore admins logging into the cms back end directly?

When an admin logs in and edits a record, we get the following error;



Notice: Undefined index: listPageUrl in /homepublic_html/cmsadmin/plugins/redirect.php on line 17 redirectBrowserToURL: No url specified!

Re: [usadomains] PHP Redirect on Save

By Jason - July 22, 2012

Hi,

If you're using the same code as above, you can get the plugin to stop running the function if the current user is an admin.

EXAMPLE:

function _plugin_redirectonsave($tableName, $action) {
global $CURRENT_USER;

if ($tableName != 'claims_submission') { return; } // only run on accounts tabl
if ($action != 'list') { return; } // only run on list
if ($CURRENT_USER['isAdmin']) { return; }


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] PHP Redirect on Save

By usadomains - July 22, 2012

Thanks Jason!

Awsesome! That did the trick, it now redirects users, and ignores admins. perfect!

Really impressed that you took the time to reply over a weekend.