post by larasmith on Sep 10, 2021

Does anyone know how to do a full page reload for GroceryCRUD Enterprise Version: 2.7.9?

I have tried the following:

  1. Use of header(“Location:”)
  2. Use of redirect(“controller/functionname”)
  3. Use of echo to add javascript that reloads the page:
    echo '<script>
            top.window.location=http://mysite/somepage.php";
            die;
          </script>';

Thank you in advance!

post by johnny on Sep 12, 2021

Hello @larasmith ,

The code that you are trying to apply it is blocked by the JavaScript that we use as this can cause XSS attacks. On the other side, you can use the JavaScript callbacks that we have here: unsetAutoloadJavaScript | Grocery CRUD - A PHP CRUD Generator Library

For example:

$(document).ready(function () {
    $('.gc-container').groceryCrud({
        callbackAfterUpdate: function (currentForm) {
            window.location = 'http://mysite/somepage.php';
        },
    );
});

Please keep in mind that if you upgrade to the latest Grocery CRUD Enterprise, you can also use the RedirectResponse class as per documentation here: Full Page Redirection | Grocery CRUD - A PHP CRUD Generator Library

Regards
Johnny

post by larasmith on Sep 14, 2021

Thank you for this response :blush:
I was not able to apply it though because I already have a workaround:

      $crud->callbackAfterInsert(function ($stateParameters) {
          $this->m_ImportDatabase->addHistory($stateParameters->insertId);

          $msg = '<script>
                    $(document).ready(function () {
                      $(".gc-error-modal-dialog").hide();
                    });
                    
                    top.location.reload();
                  </script>';

          return (new \GroceryCrud\Core\Error\ErrorMessage())->setMessage($msg);
      });  

In the script, I hide the container of the error dialog box then triggered the reload.
It’s not proper though but does the work :sweat_smile:

post by johnny on Sep 14, 2021

Oh god, you literally hacked the system and find something that I haven’t thought :slight_smile:

2 years later

post by Ali123 on Apr 27, 2023

To perform a full page reload in GroceryCRUD Enterprise Version 2.7.9, you can use the following code:

phpCopy code

redirect(current_url(), 'refresh');

This code will redirect the current URL to itself with the ‘refresh’ parameter, which will reload the page. The current_url() function is a helper function provided by CodeIgniter, which returns the current URL.

Here is an example of how you can use this code:

phpCopy code

public function my_function()
{
    // Some code here...
    
    redirect(current_url(), 'refresh');
}

You can also use the header() function to perform a full page reload, like this:

phpCopy code

header("Location: " . current_url());

This will redirect the current URL to itself using the Location header, which will cause the browser to reload the page.

I hope this helps! Let me know if you have any further questions.

6 months later

post by shelterdrown on Oct 26, 2023

1 / 6
Sep 2021