Hi everyone,
I’m working on a project where I need to implement functionality to transfer points between users. I’ve tried several solutions, but I’ve run into some technical issues that I haven’t been able to resolve. Below, I’ll describe what I’ve done so far and the challenges I’m facing. I hope someone can guide me or suggest an alternative solution.
Option 1: Using Webform
Initially, I created a form using the Webform module to manage point transfers. The form includes two main fields:
- A field to enter the points to be transferred.
- A field to validate the available points in the user’s account (using tokens).
With the Webform Validation module, I successfully implemented a validation to ensure users cannot send more points than they have available. This part works correctly.
However, when I try to integrate this form with Webform Rules to process the submitted data, I encounter several issues:
- Errors retrieving form data : Despite applying known patches, errors related to loading the data persist.
- User reference fields not recognized : User reference fields are not loaded correctly in Rules, making it impossible to complete the transfer.
Due to these issues, I’ve decided to set aside this option for now.
Option 2: Creating a Content Type
As an alternative, I created a content type called Transfer with the following fields:
- User reference : To select the recipient user.
- Points to transfer : A numeric field where the user enters the number of points they want to transfer.
The problem here is that I can’t implement effective validation between the fields. Unlike Webform, the Field Validation module does not allow direct comparison between two fields (e.g., validating that the entered points do not exceed the available points in the user’s account).
I’ve tried using Rules to perform this validation, but I’ve encountered another obstacle:
- User profile fields not available in Rules : To store the available points, I created a text field in the user profile with a token placeholder. However, this field does not appear as an option in the Rules data selector, preventing me from comparing it with the “Points to transfer” field.
Question
Does anyone have any ideas on how I can resolve this issue? I’d like to know if there’s a way to:
- Make user profile fields available in Rules.
- Implement effective validation between fields using Rules or any other module.
- Suggest viable alternatives to achieve the functionality of transferring points between users.
Any advice or suggestions would be greatly appreciated. Thanks in advance!
Comments
Hi willowf.
First let me say what you are trying to do would be SO MUCH EASIER if you wrote a custom module that provides a form, and then simply transfers the points using the userpoints API functions that already exist. This would be a simple module to write.
If you still want to stick to these approaches, I need to know what you mean by "Make user profile fields available in Rules". "User profile" refers to the user page provided by Backdrop core? Or are you talking about the contrib module "Profile"?
All fields attached to the core user entities are available in Rules, so I'm not sure I understand why you area asking how to make them available. Perhaps if you posted the Rule here I can check?
I have succeeded, I have achieved my second simple module, a form in a block that sends and subtracts points.... I will continue testing to see if there are any errors
Thanks for the motivation
Great! This is how I got started developing for D7, by writing small modules to do things that would take a lot of work to a accomplish otherwise, or would be impossible to do.
Hello @argiepiano,
I've been running several tests, some of them a bit confusing, haha, sorry about that!
What I'm trying to do is create a points transfer system using Webform. The idea is to use Rules to assign or deduct points from users. However, I ran into an issue: the numeric field in Webform doesn't work in the Rules data selector because the action to add points only accepts integers.
(To solve thi experience creating a content type called "Transfer," and with this approach, I managed to get the selector to accept the numeric field. The challenge now is to validate two fields in the form: the points to transfer and the available points.)
Regarding the module, I'm going to try to develop it, although I must admit I'm quite a novice when it comes to programming.
Additionally, the Webform Rules module has been giving me several errors related to undefined functions.
About the user fields I tried something but I discarded it.
Re: webform rules. I'd suggest you create an issue in the issue queue for the module on GitHub.