Jump to content


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

list redirect insert redirect update redirect

  • Please log in to reply
24 replies to this topic

#1 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,038 posts
  • LocationLondon

Posted 17 April 2012 - 10: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:

for insert:
   $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">
		 '
   );


for update:
   $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">
		 '
   );

Posted Image

#2 Kenta Saito

Kenta Saito

    Advanced Member

  • Members
  • PipPipPip
  • 34 posts
  • LocationTokyo JAPAN

Posted 02 May 2012 - 02:53 AM

Nice. That's what I want!

Edit Signature TEST

#3 Tim

Tim

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 03 May 2012 - 05:50 AM

awesome! thank you very much.

#4 xcoder

xcoder

    Member

  • Members
  • PipPip
  • 21 posts

Posted 31 May 2012 - 05:34 PM

thanks man...That fixed it

#5 acontreras

acontreras

    Newbie

  • Members
  • Pip
  • 1 posts

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

#6 Matt

Matt

    Member

  • Members
  • PipPip
  • 14 posts

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">');


#7 vin_vin

vin_vin

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 10 August 2012 - 08:23 AM

Thats Brillaint ! Thank you !!!!!!

#8 livewire

livewire

    Member

  • Members
  • PipPip
  • 13 posts

Posted 18 November 2012 - 06:17 PM

where do i need to add the above code?

#9 Wilman Bhigu

Wilman Bhigu

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 21 November 2012 - 03:31 AM

Great work!

#10 DREON

DREON

    Advanced Member

  • Members
  • PipPipPip
  • 118 posts

Posted 05 December 2012 - 11:35 AM

sir johnny where can put that code? thnx

#11 yepwingtim

yepwingtim

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 08 August 2013 - 09:05 PM

put it on the insert callback



#12 mariselvam

mariselvam

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 16 October 2013 - 11:10 AM

its not working for me :(



#13 Felipe Matos

Felipe Matos

    Member

  • Members
  • PipPip
  • 11 posts

Posted 12 February 2014 - 06:04 PM

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



#14 Pedro Nogueira

Pedro Nogueira

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 09 August 2014 - 06: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


#15 Dmytro Tymoshenko

Dmytro Tymoshenko

    Newbie

  • Members
  • Pip
  • 1 posts

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)))


#16 Kinon

Kinon

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 07 February 2015 - 12: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);

}



#17 Lucas

Lucas

    Advanced Member

  • Members
  • PipPipPip
  • 42 posts
  • LocationMedellin - Colombia

Posted 03 May 2015 - 04: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();
    }


#18 Paul Savostin

Paul Savostin

    Advanced Member

  • Members
  • PipPipPip
  • 229 posts
  • LocationUkraine

Posted 10 May 2015 - 03:14 PM

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



#19 w0w

w0w

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 19 June 2015 - 04:13 AM

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



#20 jcasanova

jcasanova

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts

Posted 12 December 2015 - 12:16 AM

not working for me =( 1.5.0 

 

any other solution?






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users