⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

[WORKAROUND] Redirect to the list after insert/update without changing the core functionality of GC



web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 17 April 2012 - 22:52 PM

I know this is not a proper way to do it but if you want to have a redirection add insert and/or update operation without changing the functionality of grocery CRUD you can simply do:

[b]for insert:[/b]

$crud->set_lang_string('insert_success_message',
'Your data has been successfully stored into the database.<br/>Please wait while you are redirecting to the list page.
<script type="text/javascript">
window.location = "'.site_url(strtolower(__CLASS__).'/'.strtolower(__FUNCTION__)).'";
</script>
<div style="display:none">
'
);



[b]for update:[/b]

$crud->set_lang_string('update_success_message',
'Your data has been successfully stored into the database.<br/>Please wait while you are redirecting to the list page.
<script type="text/javascript">
window.location = "'.site_url(strtolower(__CLASS__).'/'.strtolower(__FUNCTION__)).'";
</script>
<div style="display:none">
'
);

Kenta Saito
  • profile picture
  • Member

Posted 02 May 2012 - 02:53 AM

Nice. That's what I want!

visioncoding
  • profile picture
  • Member

Posted 03 May 2012 - 05:50 AM

awesome! thank you very much.

xcoder
  • profile picture
  • Member

Posted 31 May 2012 - 17:34 PM

thanks man...That fixed it

acontreras
  • profile picture
  • Member

Posted 05 July 2012 - 09:23 AM

Great tool... Thanks a lot!

There is anyway to get the primary key of the inserted record?

I want to make the redirection to another function of another controller, but I don't know how to do this with out affecting grocerycrud's library.

For example:

$crud->set_lang_string('insert_success_message',
'Your data has been successfully stored into the database.<br/>Please wait while you are redirecting to the list page.
<script type="text/javascript">
window.location = "'.site_url($controller.'/'.$function.'/'.$primary_key).'";
</script>
<div style="display:none">
'
);



Thanks in advance for your help

Matt
  • profile picture
  • Member

Posted 18 July 2012 - 10:36 AM

I made a small modification so that the redirect only happened when they asked to save (not save to list). Im doing this so I can default some of the new record to the choices of the last save using sessions.


$crud->set_lang_string('insert_success_message',
'Your snap has been successfully saved.
<script type="text/javascript">
if(window.location.pathname=="/snaps/add")
{
window.location = "/snaps/add";
}
</script>
<div style="display:none">');

vin_vin
  • profile picture
  • Member

Posted 10 August 2012 - 08:23 AM

Thats Brillaint ! Thank you !!!!!!

livewire
  • profile picture
  • Member

Posted 18 November 2012 - 18:17 PM

where do i need to add the above code?

Wilman Bhigu
  • profile picture
  • Member

Posted 21 November 2012 - 03:31 AM

Great work!

DREON
  • profile picture
  • Member

Posted 05 December 2012 - 11:35 AM

sir johnny where can put that code? thnx

yepwingtim
  • profile picture
  • Member

Posted 08 August 2013 - 21:05 PM

put it on the insert callback


mariselvam
  • profile picture
  • Member

Posted 16 October 2013 - 11:10 AM

its not working for me :(


Felipe Matos
  • profile picture
  • Member

Posted 12 February 2014 - 18:04 PM

I have the same doubt the acontreras.... how to pass the primary key.... somebody knows?


Pedro Nogueira
  • profile picture
  • Member

Posted 09 August 2014 - 18:24 PM

Hi, I'm a newbie with grocerycrud, I'm trying to use this code, but it doesn't work:

 

$crud->callback_after_insert(array($this, 'redirect'));

 

function redirect($post_array,$primary_key)
{
$crud->set_lang_string('insert_success_message',
'Your data has been successfully stored into the database.<br/>Please wait while you are redirecting to the list page.
<script type="text/javascript">
window.location = "'.site_url('actions/actions_/add').'";
</script>
<div style="display:none">
'
);
  }
 
On firebug console I get : "SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data"
 
Thanks for your help

Dmytro Tymoshenko
  • profile picture
  • Member

Posted 13 January 2015 - 11:36 AM

Hi everybody! Thx for the code, you saved my day! =)

I've met the same problem. i need the primary_key to use in redirect. I don't know how to use it with insert, but for update this helped :

 

  $crud->set_lang_string('update_success_message',
            'Информация успешно сохранена.<br/>Пожалуйста дождитесь переадресации.
            <script type="text/javascript">
             window.location = "'.base_url('group/group_redirect_day/'.$this->uri->segment(count($this->uri->segments))).'";
		 </script>
		 <div style="display:none">
		 '
        );

This will return the primary_key :

 

$this->uri->segment(count($this->uri->segments)))

Kinon
  • profile picture
  • Member

Posted 07 February 2015 - 00:01 AM

This works:

 

$crud->callback_after_insert(array($this, 'product_after_insert'));

$crud->set_lang_string('insert_success_message',
            'You're being redirected to complete info.<script type="text/javascript">
            window.location = "'.site_url('product/index/edit/'.$this->session->userdata('liid')).'";
            </script>');

function product_after_insert($post_array, $primary_key) {

...

$this->session->set_userdata('liid', $primary_key);

}


Lucas
  • profile picture
  • Member

Posted 03 May 2015 - 16:17 PM

i Tried to use your code but always showed  the last insert  id but not the actual id.

 

I used This:

 

Controler

        $crud->set_lang_string('insert_success_message', 'Sus datos se han almacenado con éxito en la base de datos. <br/> Espere mientras está redirigiendo a la página de la lista.
		 <script type="text/javascript">setTimeout(function() {
                  window.location = "' . site_url(strtolower("solicitudes_redes") . '/' . strtolower("redirect_before_insert")) . '";
                    }, 1000);
		 </script>
		 <div style="display:none">
		 '
        );

      public function redirect_before_insert(){
        $row = $this->Solicitud_red_model->obtener_numero_rows();
        $this->ver_solicitud_red($row->id_solicitud_red);
    }

And Model

    function obtener_numero_rows() {
        $query = $this->db->get('solicitud_red');
        return $query->last_row();
    }

Paul Savostin
  • profile picture
  • Member

Posted 10 May 2015 - 15:14 PM

Is this method work with custom insert/update? (callback_update/callback_insert)


w0w
  • profile picture
  • Member

Posted 19 June 2015 - 04:13 AM

not work for me after updating to 1.5.1. Any work around? thanks


jcasanova
  • profile picture
  • Member

Posted 12 December 2015 - 00:16 AM

not working for me =( 1.5.0 

 

any other solution?