Skip to Content Skip to Menu

Autogenerate Username

  • mhs_cb
  • mhs_cb
  • OFFLINE
  • Posts: 53
  • Thanks: 0
  • Karma: 0
10 years 2 months ago #247636 by mhs_cb
Autogenerate Username was created by mhs_cb
I simply want to generate 10 random digits as the username at the time of registration.

I know I can do this by using CB Auto Actions. By using a Code action on the 'before registration' trigger and altering the POST of username.

Can someone be so kind as to give me a the PHP code that will alter the POST of username to 10 randomly generated digits?

Thanks in advance.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48479
  • Thanks: 8282
  • Karma: 1443
10 years 2 months ago #247771 by krileon
Replied by krileon on topic Autogenerate Username
Below topic is similar case to what you're wanting. You basically need to allow the username field on registration, set it as not required, then hide it using CSS. This allows its POST to be processed. You'd then use a code action and PHP to alter the post value on the before registration trigger. Please see the below for full example.

www.joomlapolis.com/forum/146-general/223448-joomla-2516-and-cb-191-issue?start=6#237232


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • mhs_cb
  • mhs_cb
  • OFFLINE
  • Posts: 53
  • Thanks: 0
  • Karma: 0
10 years 2 months ago #247778 by mhs_cb
Replied by mhs_cb on topic Autogenerate Username
Not sure if I should continue here or over on that post. In any case:

Exactly what I need, thanks.

2 questions:

1. How do I define the length of "uniqid"
2. Can I use CB Substitutions for pretext and posttext in order to add other fields that have been entered?

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48479
  • Thanks: 8282
  • Karma: 1443
10 years 2 months ago #247784 by krileon
Replied by krileon on topic Autogenerate Username

1. How do I define the length of "uniqid"

You can't, it has no such functionality. You can use substr to cut it short or look into other PHP methods for generating strings so you get a unique string at your exact desired length.

2. Can I use CB Substitutions for pretext and posttext in order to add other fields that have been entered?

Yes, all CB Auto Action types support substitutions. This includes substitutions inside of a Code action.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • mhs_cb
  • mhs_cb
  • OFFLINE
  • Posts: 53
  • Thanks: 0
  • Karma: 0
10 years 2 months ago - 10 years 2 months ago #247790 by mhs_cb
Replied by mhs_cb on topic Autogenerate Username
Ok, I'm no PHP expert here (so no laughing out loud). Will this work in generating a random string that is 6 digits long? (with a predefined pre-text and post-text.
Code:
$_POST['username'] = 'pretext' . mt_rand(99999, 999999) . 'posttext';

I am assuming this will not ensure that it's a unique username?
Last edit: 10 years 2 months ago by mhs_cb.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48479
  • Thanks: 8282
  • Karma: 1443
10 years 2 months ago #247841 by krileon
Replied by krileon on topic Autogenerate Username
That's 1 way to do it. Best I can suggest is try it and see what happens.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum