Inside V5: Custom Profile Fields
In this entry I'm going to talk about a new feature that our coders are sure to love. It is intended towards coders who have a firm understanding of JavaScript.
One issue that has come up for a lot of coders is the desire to store data on a per-user basis and be able to access it on any page. Many codes such as RPG codes, shops, and more need this functionality. This has proven difficult to implement, until now.
In version 5, every user has 10 custom profile fields that can store data. But what's better than the fact that these exist, is how you can modify them. Using AJAX we give you the power to update data in any of these 10 custom fields from any page.
We've designed a JavaScript function pb_set_custom_field that allows you to pass in parameters to update these custom fields. There are 3 parameters that need to be passed:
A request would look something like this:
Wondering what that transport parameter is? Read about that here.
Now, you know how to save information, but how do you access it?
On every page there is a JavaScript array called pb_user_custom. To access the data for custom field 1 you would simply use the JavaScript variable pb_user_custom[1]. Likewise, if you had stored data in the custom field 7 you would then access the JavaScript variable pb_user_custom[7].
That's all there is to it!
In addition to this functionality, we will be giving admins the power to optionally display custom profile fields in the mini profile as well as your regular profile. There will be an area where you can "name" each field (so it doesn't just show up as "Custom Field 1").
Also, you will have the option to let users change their custom profile fields themselves. If you choose to let your members edit their custom profile fields, you can specify for each field if only certain options are valid (e.g. there will be a drop down box for them to choose), or you can opt to let them type in their own value.
One issue that has come up for a lot of coders is the desire to store data on a per-user basis and be able to access it on any page. Many codes such as RPG codes, shops, and more need this functionality. This has proven difficult to implement, until now.
In version 5, every user has 10 custom profile fields that can store data. But what's better than the fact that these exist, is how you can modify them. Using AJAX we give you the power to update data in any of these 10 custom fields from any page.
We've designed a JavaScript function pb_set_custom_field that allows you to pass in parameters to update these custom fields. There are 3 parameters that need to be passed:
field # - The number of the custom field you wish to update. This value will be anything from 1 to 10.
value - The new value you wish to save, maximum 100 characters.
handler object - This is a javascript object that you create which has 3 functions: sent, success, fail. The sent function will be called when the AJAX request is sent, success will be called if the result is a success, and fail will be called if the request failed.
A request would look something like this:
<script type="text/javascript">
function sendRequest(field,value) {
if(value.length > 100) {
// value is too big (max 100 char)
alert("Value is too big.");
}
pb_set_custom_field(field,value,new ajaxHandler());
}
function ajaxHandler() {}
ajaxHandler.prototype.sent = function() {
alert("Sent AJAX request.");
};
ajaxHandler.prototype.success = function(transport) {
alert("Request successful. Response was: "+transport.responseText);
};
ajaxHandler.prototype.fail = function(transport) {
alert("AJAX request failed.");
};
sendRequest(1,'New value!');
</script>
Wondering what that transport parameter is? Read about that here.
Now, you know how to save information, but how do you access it?
On every page there is a JavaScript array called pb_user_custom. To access the data for custom field 1 you would simply use the JavaScript variable pb_user_custom[1]. Likewise, if you had stored data in the custom field 7 you would then access the JavaScript variable pb_user_custom[7].
That's all there is to it!
In addition to this functionality, we will be giving admins the power to optionally display custom profile fields in the mini profile as well as your regular profile. There will be an area where you can "name" each field (so it doesn't just show up as "Custom Field 1").
Also, you will have the option to let users change their custom profile fields themselves. If you choose to let your members edit their custom profile fields, you can specify for each field if only certain options are valid (e.g. there will be a drop down box for them to choose), or you can opt to let them type in their own value.
Labels: Version 5

2 Comments:
I like this feature. Does this mean AJAX is allowed to be utilized now?
By
Greg, At
March 16, 2008 2:37 PM
Were About To Find Out.....
By
Jay, At
May 20, 2008 12:34 AM
Post a Comment
<< Home