MyBB Community Forums

Full Version: insert username into posts with mycode
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm wanting to use the mycode for the user to put their own name at the top of posts, is there a way I can do this with mycode?
You can use MyBB's MyCode feature to allow users to add their own name at the top of their posts. Here's how you can do it:

1. Go to your MyBB Admin Control Panel (ACP) and click on the "Templates" tab.
2. Select the template you want to edit. For example, if you want to add the name field to the "New Reply" page, you can select the "newreply" template.
3. Find the location where you want the name field to appear. You can use the MyCode tag "[name]" to insert a text input field for the user's name. For example, you can add the following code to the "newreply" template to add the name field at the top of the post:

<div class="name-field">
<strong>Your Name:</strong> [name]
</div>

4. Save the template and the changes will be applied to the relevant pages on your forum.

Note that MyCode tags are processed by MyBB and converted into HTML when the post is displayed. The "[name]" tag will be replaced with an HTML input field where the user can enter their name. You can also add additional CSS styles to the "name-field" class to customize the appearance of the name field.
Thank you for your reply! I guess I'm not understanding how I add this to the mycode area. I'm wanting users to be able to use the [name] in the post itself, not really inside a template.
* HLFadmin says

you might be able to use the /me code for this purpose.
Requires it start a line, and it highlights the rest of the line.
And /me must be followed by at least 1 character.

First line in post is
/me says
I didn't know that was a thing, but I don't think it will quite be what I am looking for, thank you thought!
(2023-03-20, 12:21 PM)HLFadmin Wrote: [ -> ]* HLFadmin says

you might be able to use the /me code for this purpose.
Requires it start a line, and it highlights the rest of the line.
And /me must be followed by at least 1 character.

First line in post is
/me says

Is this a default/built-in thing in mybb? I just tried it on another mybb site and it didn't work - could you expand on what this is?
It's a core function in class_parser.php that won't work if /me mycode in posts is not enabled.
Check setting at AdminCP / Clickable Smilies and BBCode / Allow Me Mycodes

 208          // Replace "me" code and slaps if we have a username
 209          if(!empty($this->options['me_username']) && $mybb->settings['allowmemycode'] == 1)
 210          {
 211              global $lang;
 212  
 213              $message = preg_replace('#(>|^|\r|\n)/me ([^\r\n<]*)#i', "\\1<span style=\"color: red;\" class=\"mycode_me\">* {$this->options['me_username']} \\2</span>", $message);
 214              $message = preg_replace('#(>|^|\r|\n)/slap ([^\r\n<]*)#i', "\\1<span style=\"color: red;\" class=\"mycode_slap\">* {$this->options['me_username']} {$lang->slaps} \\2 {$lang->with_trout}</span>", $message);
 215          }