Redirecting to another page inside a PHP script in Sugar

bsoremsugar —  January 18, 2013 — 8 Comments

Here’s a great forums question

I have a form when clicking on it need to go other.php file-available in crm root folder.

I have given header(‘Location: other.php’); – It is not working.

I think need to provide action like header(‘Location: index.php?action=other’); – But some where need to register this file.

Kindly give your views for redirection issue.

Using the header() method can be challenging in Sugar, as you are dependent on whether or not output from the script has been returned to the user. A better choice, as pointed out by Sugar Community Member item, is to call the SugarApplication::redirect() method as shown below…

This will do a redirect using the PHP header() call with a 301 redirect if you can, otherwise will send a javascript call to redirect at that level if you can’t.

8 responses to Redirecting to another page inside a PHP script in Sugar

  1. 

    Just used this today. Thanks!

  2. 

    Additionally you could use http_build_query to secure your parameters:


    $queryParams = array(
    'module' => 'DetailView',
    'action' => 'Accounts',
    'record' => $recordId,
    );

    SugarApplication::redirect('index.php?' . http_build_query($queryParams));

  3. 

    Awesome. Worked with this today. Typo in the module/action strings, though :)

  4. 

    I make a registration form on PHP and displaying inputs to another page. here I want to generate “username already exist error” and want to redirect back to registration form page with an error message along with the form that “username already exist”. how to do it??

Trackbacks and Pingbacks:

  1. redirecting to other page - January 23, 2013

    [...] [...]

  2. Showing error messages and redirecting in SugarCRM – The Aust Gate - February 2, 2013

    [...] other scripts in Sugar. John Mertic, Sugar’s community managers, wrote a short post about the SugarApplication redirect on the Sugar blog. Essentially it creates a 301 redirect (as a wrapper around the PHP header() [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s