1. msreyes
  2. General
  3. Wednesday, September 08 2021, 08:01 PM
I have a field that is 6 numbers.... in my case this is their membership number.

I would like to ensure:

  • User enters only numbers.
  • If their membership number is "1251" populate the field with leading zeros and put that into the database (eg: "001251";).



How do I do this?
admin Accepted Answer
Admin
Hi and sorry for late reply, we had a technical issue, so we have not received a ticket notification.

This is not possible with a field of type Number, you should use a field of type Text and a simple plugin that fills value with 0.

1) Configure Text field to accept only numbers
Configure options like screenshot, with a custom format like [0-9]{6} then it will accept only numbers (max 6 numbers)

2) Write the plugin to add zero to the number
- Download, Install and Enable Skeleton Plugin (you will find it at http://docs.easy-profile.com/index.php/article/triggers)
- Open file /plugins/jsn/skeleton/skeleton.php
- remove samples functions: triggerFieldAvatarUpdate, triggerProfileUpdate
- add function like this:
public function triggerProfileUpdate($user,&$data,$changed,$isNew){ 
if(!empty($data['alias_of_the_field'])) // remove this line if you allow empty value, so it will become like 000000
$data['alias_of_the_field'] = str_pad($data['alias_of_the_field'], 6, "0", STR_PAD_LEFT);
}
Attachments (1)
  1. more than a month ago
  2. General
  3. # 1
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.