Gravity forms add points from number field.

front page Forums Community Gravity forms add points from number field.

This topic contains 17 replies, has 4 voices, and was last updated by Avatar CarlenY 2 weeks, 2 days ago.

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #12665
    Avatar
    Simon Bame

    Hello,

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

    #12689
    Avatar
    WPExperts

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

    #12691
    Avatar
    Simon 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.

    #12703
    Avatar
    WPExperts

    Yeah of course. The fields visibility should have no effect. myCRED only checks that it exists and that it’s not zero / empty.

    #12757
    Avatar
    Simon 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.

    #12763
    Avatar
    WPExperts

    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.

    #12771
    Avatar
    Simon 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.

    #12775
    Avatar
    Simon Bame

    Or maybe I got the code in the wrong place, where is it supposed to go?

    #12776
    Avatar
    Simon 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.

    #12781
    Avatar
    WPExperts

    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.

    #12782
    Avatar
    Simon 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.

    #12783
    Avatar
    WPExperts

    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

    #12786
    Avatar
    Simon Bame

    Just double checking that this goes into the functions.php of my theme?

    Thanks again.

    #12801
    Avatar
    WPExperts

    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.

    #12807
    Avatar
    Simon Bame

    Hi Gabriel,

    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.

    Kind regards,
    Simon.

Viewing 15 posts - 1 through 15 (of 18 total)

You must be logged in to reply to this topic.

11