ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Getting SafeCracker to update 2 different channels with a single submit

May 13, 2012 8:58am

Subscribe [1]
  • #1 / May 13, 2012 8:58am

    ChiefAlchemist

    913 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

  • #2 / May 13, 2012 12:57pm

    Bhashkar Yadav

    727 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

  • #3 / May 13, 2012 8:07pm

    ChiefAlchemist

    913 posts

    Hello Bhashkar

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

    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.

  • #4 / May 13, 2012 8:36pm

    ChiefAlchemist

    913 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.

  • #5 / May 13, 2012 9:24pm

    Bhashkar Yadav

    727 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 😊.

    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,

  • #6 / May 14, 2012 9:41am

    ChiefAlchemist

    913 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.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases