1

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?

mheavers
  • 29,530
  • 58
  • 194
  • 315
  • Where are you storing the votes? Are you storing individual votes or just incrementing the tally? If you store the votes in a votes table then you can store the member_id of the voter as well. This has the additional benefit of allowing you to not have to add another custom member field every time you need to have another election contest. You may also wish to evaluate some of the voting add ons that exist for EE. At the very least you will learn how this sort of thing has been handled before. – AllInOne Jul 10 '12 at 11:11

1 Answers1

2

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.

Derek Hogue
  • 4,589
  • 1
  • 15
  • 27
  • Thanks - that is helpful. I guess my question was more of a two parter, and I think the question that needs to be answered first is whether or not you can set custom member field values or not. If you can't, it won't do me any good to develop an extension for safecracker I guess. – mheavers Jul 10 '12 at 15:27
  • 1
    Setting custom member field values is as simple as updating the `exp_member_data` field. Very doable in an extension. – Derek Hogue Jul 10 '12 at 15:54