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?
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”.
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.
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.
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.
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.
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.
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/2S0LSRF3
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.
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.
This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
Strictly Necessary Cookies
Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.
If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.