- This topic has 17 replies, 4 voices, and was last updated 3 months ago by CarlenY.
- January 19, 2015 at 18:29 #12665Simon Bame
I am using Gravity forms. (I have also posted here)
I have a form that has a number field on it which the user inputs the number of points they earned from a game. I then would like this number to be added to their myCRED balance. Is there a way to do this and if so how?
Any help will be greatly appreciated.
Thank you in advance.
SimonJanuary 20, 2015 at 18:00 #12689WPExperts
When awarding points for form submissions, myCRED will check if there is a field that has the label “mycred_amount”. If this field exists, this amount is awarded instead of the amount you set in the hook.
If not, myCRED will default to your hook preferences. Note that the hook must be enabled and you must set an amount that is not zero for this to work, even if you want to set the amount via forms only! If you set the amount to zero in the hook, myCRED will assume you want to disable the hook.
You can do the same things with the log entry by having a field label called “mycred_entry”.January 20, 2015 at 18:45 #12691Simon Bame
I see, but can I set this field (mycred_amount) to be hidden but be pre-populated by the field points earned? which is on the same form.January 21, 2015 at 01:16 #12703WPExperts
Yeah of course. The fields visibility should have no effect. myCRED only checks that it exists and that it’s not zero / empty.January 21, 2015 at 21:43 #12757Simon Bame
Ok, so I have managed to get mycred_amount field to populate dynamically using the advanced option and Allow field to be populated dynamically and then putting in the field number using a code snippet (below) I found. But because it seems to populate the field after submission it doesn’t update the user’s balance and no points are allocated at all even for submitting the form. But it shows in entries of Gravity forms that the amount box was filled out automatically.
This is the snippet I found here https://gist.github.com/spivurno/7029518
I did check that the mycred_amount works by putting an amount in default value and it did update the balance.
But having trouble getting it to update from the field points earned.January 22, 2015 at 12:30 #12763WPExperts
The validation hook that code snippet uses fired before myCRED so it should populate your field before myCRED does it’s thing. I would check that the field label is set to “mycred_amount” (without quotes, case sensitive).
Alternativly you could add a hidden field to your form, use the label “mycred_amount” and set the default value.January 22, 2015 at 15:03 #12771Simon Bame
The same field works when I put in a number in the default value and it adds to the balance fine, but it doesn’t work when I use the populate dynamically option in advanced with the field points earned. (The mycred_amount is a hidden field but have tried it not hidden as well.)
The only problem with setting the default value is that the points earned changes depending on the user input. Not sure how to proceed maybe it is not filling out the default value but the field itself if that makes sense?
Thank you for your help so far, it is greatly appreciated.January 22, 2015 at 15:28 #12775Simon Bame
Or maybe I got the code in the wrong place, where is it supposed to go?January 22, 2015 at 16:19 #12776Simon Bame
Ignore that last message as the entry does update but balance does not update and snippet is in functions.php.
Please see message before.January 22, 2015 at 17:41 #12781WPExperts
I am at a bit of a loss with that code snippet, Gravity forms is not my strongest skill as I have very little experience with it. Are you sure the fields “defaultValue” field is populated because that is what the hook is looking for.January 22, 2015 at 17:49 #12782Simon Bame
Is there any way of changing the hook to look at the value in the field rather than default value as the code snippet places it into the field (not the default value)
That is where the problem is.January 22, 2015 at 18:03 #12783WPExperts
IF all points for gravity form submissions are based on this setup, then you could disable the hook on the myCRED > Hooks page and add the following code snippet in instead.
It will payout points if the amount and entry fields are set. I am unsure what field values are available here so I just used “value”. You might need to change this to the appropriate one.
http://pastebin.com/2S0LSRF3January 22, 2015 at 18:36 #12786Simon Bame
Just double checking that this goes into the functions.php of my theme?
Thanks again.January 23, 2015 at 01:25 #12801WPExperts
Yes, unless otherwise stated, code examples / snippets goes into your child theme’s functions.php for if you are not using a child theme your theme’s functions.php file.January 23, 2015 at 14:18 #12807Simon Bame
Unfortunately the code didn’t work and still at a loss in getting the field value. I have asked for support from someone who works with Gravity Forms and creates snippets which is the same chap that created the snippet that I posted above. So hopefully will have some success.
I would like to thank you very much for your quick support and a fantastic plugin, you are correct in having the label Legend as you are.
myCred is a wonderful plugin and is the only one which offers these features.
I will let you know when I get a response so you can pass the support on to others if required.
You must be logged in to reply to this topic.