• Resolved Mauricio Gofas

    (@mauriciogofas)


    Hello!
    I would like to use the value entered for admin in a text field in a form editor to adjust the users balance.

    To apply custom points of custom types of points, I thought of using CSS class to distinguish fields which adds points to a particular type of points.

    Please do not laugh, this is a bit of what I am researching to create this plugin:

    <?php
    
    			add_action( 'gform_after_update_entry', array( $this, 'adjust_amount_field' ), 10, 2 );
    			function adjust_amount_field( $form, $lead, $field, $value ) {
    
    			// Requiremetns
    	        if ( $form_id = $entry['id'] || ! current_user_can( 'edit_users' ) ) return;
    
    			$field_class = explode(' ', $field['cssClass']);
    			$field_class_matches = array_intersect($field_class, array('points-type-A'));
    
    			$field_class = explode(' ', $field['cssClass']);
    			$field_class_matches = array_intersect($field_class, array('points-type-B'));
    
    		    // Get the user object
    	        $user = get_userdata( absint( $lead['created_by'] ) );
    	        if ( ! isset( $user->ID ) ) return;
    
    			// Get Field Value
    			add_filter("gform_get_field_value", "get_field_value", 10, 3);
    
    			function get_field_value($value, $lead, $field){
    
        		//Aply Field Value in Amount adjust
    			//?????????????????????????????????
    
        		if(is_array($value)){
    
            	foreach($value as $key => $input_value){
    
                $value[$key] = mycred_amount($input_value);
    
    }
    
            	return $amount = sanitize_text_field( $value );
    
    }
    				// mycred = Amount override
    				if ( $field['label'] || ! $field_class['points-type-A'] == 'points-type-A_amount' ) {
    				$amount = sanitize_text_field( $field = $value );
    				}
    
    				if ( $field['label'] || ! $field_class['points-type-B'] == 'points-type-B_amount' ) {
    				$amount = sanitize_text_field( $field = $value );
    				}
    
    				// Override entry at Lead ID
    				if ( $field['label'] == 'mycred_entry' ) {
    				$entry = sanitize_text_field( $field = $lead['id'] );
    			}
    		}
    	}
    ?>

    The idea is:

    1 – Admin creates text field visible only to admins (“Points”). Field with class “points-type-A” add points to “points-type-A” custom point type;

    2 – While reading a message, admin can adjust the score of the user filling out the value in the text field “Points” and updating the entry;

    Images to illustrate,
    A – Create form:
    http://www.starsclubbrasil.com.br/up/sites/163/Captura-de-Tela-2014-06-13-%C3%A0s-00.57.54.png

    B- Adjust Balance:
    http://www.starsclubbrasil.com.br/up/sites/163/Captura-de-Tela-2014-06-13-%C3%A0s-00.57.54.png

    Thanks since right now!

    https://wordpress.org/plugins/mycred/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author myCred

    (@designbymerovingi)

    I am sorry but I do not understand what you are trying to do.
    You want to adjust users balances based on a CSS value?

    Both images A and B are the same.

    Thread Starter Mauricio Gofas

    (@mauriciogofas)

    Sorry, the correct images

    A – Create form:
    http://www.starsclubbrasil.com.br/up/sites/163/Captura-de-Tela-2014-06-13-%C3%A0s-00.57.54.png

    B- Adjust Balance:
    http://www.starsclubbrasil.com.br/up/sites/163/Captura-de-Tela-2014-06-13-%C3%A0s-01.01.26.png

    I want to adjust users balances based on the value (number) entered into a text field with a predetermined especific CSS class.

    Eg.: Text field class points-type-A adjust balance of myCRED-points-type-A-type for entry creator;
    Text field class points-type-B adjust balance of myCRED-points-type-B-type for entry creator;

    The css class is just to know which textfield adds points for especific custom point type, thus one need not specify the id of the text field.

    (I was thinking now out a way to automatically generate css class with the key ID of the point type meta key, eg:. Mycred-points-type-A-type = mycred-points-type-A css class.)

    ps.: I do not write very well in English, sorry if this is disturbing

    Plugin Author myCred

    (@designbymerovingi)

    Ok so add in a hidden field only visible to admins that states which point type you want to award.

    Then add in the field for when viewing submissions where admins enter the amount they want to add.

    Finally when the form is submitted by the admin via a button of some sorts, you apply the points according to your field values.

    Unfortunately I have very limited knowledge of Gravity Forms so I do not know how to customize fields and how form submissions would work in the admin area.

    Thread Starter Mauricio Gofas

    (@mauriciogofas)

    Hi,
    I’m not sure I understood…

    You suggest insert something like that

    mycred_amount

    and

    mycred_enty?

    in hide field?

    For custom point type would be “custompointtype_amount”?

    mycred_amount works after gform_after_submission action, for admin manually adjust amount, is necessary change the line 49 in mycred-hook-gravityforms.php:
    gform_after_submission to gform_after_update_entry?

    Thanks!

    Plugin Author myCred

    (@designbymerovingi)

    As I mentioned in this reply, you need to add a hidden form field and set the label to mycred_amount if you want to override how many points submitting the form gives. But you can set the point amount and point type via the Hook as well. If you want to give a custom amount of points, then right now you will need to use the myCRED Hook as the override I mention only works with the main point type right now.

    If you make any changes in the plugin files, you will lose these changes the next time you update the plugin! You should make changes or adjustments via your child themes functions.php file or via a custom plugin.

    Just changing a hook name is not enough. You also need to make sure that the gform_after_update_entry also has the same variables that are passed on to the gform_after_submission action. Not all hooks have the same variables. Just search the Gravity Forms plugin files for the hook you want to use and see what variables (if any) are available and then build you custom connection via those.

    Thread Starter Mauricio Gofas

    (@mauriciogofas)

    Hello Gabriel!
    It took some time but now beginning to understand, that answers my question!
    I’m studying gform_after_update_entry, gform_after_submission and actions, their variables and how to assemble the plugin to work with mycred.
    Thanks again!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Use the value of a field to adjust the user's balance (myCRED and Gravity Forms)’ is closed to new replies.