EllisLab text mark
Advanced Search
     
Getting SafeCracker to update 2 different channels with a single submit
Posted: 13 May 2012 08:58 AM   [ Ignore ]
Joined: 2008-11-19
1070 posts

Perhaps I asked the wrong question and went into too much detail in my previous post?

1) How can I get SafeCracker to update two different channels with a single submit? One would update the entry on the page, the other would create a new record in another channel.

2) Ideally, this interaction is Ajax. I’d like to avoid a complete page refresh if possible. Any thoughts on this would be helpful as well.

Thanks
Mark

 
Posted: 13 May 2012 12:57 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2011-03-18
632 posts

Hi ChiefAlchemist,

If you would like to use ajax then you can submit forms one by one with ajax with one submit button. It would be simple, submit first channel SAEF and on success of the first, submit the second.
For the field values validations, you can use JQuery validation.


Best Regards,
Bhashkar

 Signature 

Bhashkar Yadav
http://www.sidd3.com

 
Posted: 13 May 2012 08:07 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2008-11-19
1070 posts

Hello Bhashkar

Thanks. Yes, I understand in theory it’s possible. Given time and budget pretty much everything is smile

What’s not clear to me is the relationship between hidden fields SafeCracker creates, how EE handles updates, and what I would need to construct and pass to make the Ajax request.

According to the comments in jquery.form.js, a form can be created on the fly and then I could use ajaxSubmit for the second update.

I’m getting past the trauma (?) of the theory and am drilling down into the real details. Anything down and dirty in those details would be greatly appreciated.

 
Posted: 13 May 2012 08:36 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Joined: 2008-11-19
1070 posts

Hey Bhashkar

I realize this is a quick follow up but I just had (what I believe is) a breakthrough.

At the end of SafeCracker docs page

http://ellislab.com/expressionengine/user-guide/modules/safecracker/index.html

JT Thompson gives examples for using javascript to change the hidden form values. In short, BINGO!

It goes a little something like this…

The form can contain fields for both channels. Each channel will just ignore the fields that don’t apply to that channel. After the first submit on ajaxSuccess I change the channel_id to the second channel and then submit again.

I’ve tried it once. It works. i suppose there’s a bump in the road somewhere but at the moment I think I got something…I hope

Thanks again.

 
Posted: 13 May 2012 09:24 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2011-03-18
632 posts

Hi ChiefAlchemist,

Thanks for sharing this useful info.

i suppose, you have same field group for both channels that’s why this approach would work for you smile.

but there could be a different situation when both channels don’t have same field group. For that, we can use ajax submit approach.

Please share if you find anything special.


Best Regards,

 Signature 

Bhashkar Yadav
http://www.sidd3.com

 
Posted: 14 May 2012 09:41 AM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Joined: 2008-11-19
1070 posts

Actually, the quick test I ran was with two different field groups. It worked.

As I mentioned, the back-end will just ignore any “extra” fields. For example

Chan 1
f1-a
f1-b
f1-c

Chan 2
f2-c
f2-d
f2-e

Only the shared field name (“c”) would be updated in both channels. Else, Chan 1 will “accept” the fields a, b and c. And Chan 2 will do c, d and e.