Search code examples
jqueryajaxexpressionenginesafecracker

jquery / ajax / expression engine - set a custom member field within a safecracker form


I'm using jquery with expression engine to submit an ajax form, utilizing the safe cracker module, documented here:

http://expressionengine.com/user_guide/modules/safecracker/examples.html

Basically, my form allows logged in members to vote. I want them to be able to vote only once though, so I set up a custom profile data field called "voted" which I want to set to "true" once they submit the form. Is this possible? If so, how?


Solution

  • SafeCracker has an extension hook called safecracker_submit_entry_end (documentation), so you can build an extension which uses that hook, then in that hook's method do what you need to do.

    Hint: that extension hook gets passed a reference to the SafeCracker object, which is not documented ... so when you first test out the extension, simply print the object so you can see what it contains:

    function safecracker_submit_entry_end($safecracker)
    {
        print_r($safecracker); exit();
    }
    

    If you're unfamiliar with developing extensions and for ExpressionEngine, using the database class, etc, that's a whole other thing. I can post some links to get you started if that's the case.