⚠ 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

i have two actions to do after submit



hatem
  • profile picture
  • Member

Posted 01 November 2011 - 11:40 AM

hi,
i use grocerycrud 1.1.3,
i want to do two actions in after submit.

1- update table
2- add new ligne in table_histo.

note: i can do this with trigger (in database) , but i want to do this in my code.

how can i do this.

thank you

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

Posted 01 November 2011 - 19:14 PM

[quote name='hatem' timestamp='1320147627' post='18']
hi,
i use grocerycrud 1.1.3,
i want to do two actions in after submit.

1- update table
2- add new ligne in table_histo.

note: i can do this with trigger (in database) , but i want to do this in my code.

how can i do this.

thank you
[/quote]
You have to use callback_after_insert ( http://www.grocerycrud.com/crud/function_name/callback_after_insert ) and callback_after_update ( http://www.grocerycrud.com/crud/function_name/callback_after_update ) . I don't have examples for this in the website but it works with the same way as callback_before_insert . I have an example for this at: http://www.grocerycrud.com/crud/example/callback_before_insert . The only difference is that you will have two parameters in your callback the one is the post array and the other is the primary key. So your callback will be something like this


function example_callback($post_array, $primary_key_value)
{
//Your trigger goes here
}


If you have any issues or any problem with this just ask.

hatem
  • profile picture
  • Member

Posted 02 November 2011 - 14:48 PM

ok thank you,
i will try to use this

hatem
  • profile picture
  • Member

Posted 03 November 2011 - 15:52 PM

hi
i didn't success to do this.
can you please write an example.

for me i have two tables[b] file_base[/b] and[b] file_base_archive [/b], for (update) on one row of table[b] file_base[/b] i will add one row in [b]file_base_archive [/b]wich contain the old values of row updated and also the date of updating.
and for delete i will put the ligne deleted from [b]file_base[/b] in [b]file_base_archive.[/b]

[b]i think the probleme is clear [/b].

thank you in advance

jcasanova
  • profile picture
  • Member

Posted 13 April 2012 - 15:26 PM

callback_before_insert not working for me...

I added to the post_array an extra value to be added in the query and.. nothing happend and even I return an empty array and nothing.. it just added from the
data in the form

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

Posted 13 April 2012 - 21:36 PM

[member='jcasanova'] I renamed all the callback_before functions as for grocery CRUD version 1.2 . You can see it at the post: http://www.grocerycr...to-12-or-later/ or at change logs

You can also find many intrestring things at the forum "How to and FAQ": http://www.grocerycr...ow-to-and-faqs/