MyBB Community Forums

Full Version: Member Register Custom Field
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'd like to add a custom field to to the registration page and make it mandatory to answer. I see that there is a member_register_customfield template and that seems like the obvious place to add it. I tried to add a custom field that I'm displaying in the postbit template, but it doesn't seem to work. How do I get it to display on the registration page?

Thanks.
Make it a required field and it'll show up Smile
Thanks, Matt! Way too easy! Now I see in the custom field setup where it says that it will appear on the registration form.

Cosmetic question: When it shows up, the label does not have a colon after it. In the UCP, it does, though - so adding a colon to label will create two colons in the UCP. Any suggestions?
Not to double up on a post, but is there any way to default the value of a custom field?
You can make it a required field. and If you want to show it on the Post bit then Use post_bit_author_user template
(2009-06-19, 09:27 PM)mtritt Wrote: [ -> ]Cosmetic question: When it shows up, the label does not have a colon after it. In the UCP, it does, though - so adding a colon to label will create two colons in the UCP. Any suggestions?
Not to double up on a post, but is there any way to default the value of a custom field?

Oooh that would really annoy me!! Toungue I guess it's technically a bug, although tiny, I wouldn't know where to look to fix it though, doesn't seem to be in any language files...

As for a default, I think that'll need some sort of code modification, can't see any way to add a default value in the ACP.
I backtracked. I saw that member_register_customfield was using a variable called $code and then found that in member.php. It queries the database for the custom field configuration properties and then builds the field based on the field type:

For instance, here's the elseif for a custom field select box:
			elseif($type == "select")
			{
				$expoptions = explode("\n", $options);
				if(is_array($expoptions))
				{
					foreach($expoptions as $key => $val)
					{
						$val = trim($val);
						$val = str_replace("\n", "\\n", $val);
						$sel = "";
						if($val == $userfield)
						{
							$sel = "selected=\"selected\"";
						}
						$select .= "<option value=\"$val\" $sel>$val</option>";
					}
					if(!$profilefield['length'])
					{
						$profilefield['length'] = 1;
					}
					$code = "<select name=\"profile_fields[$field]\" id=\"{$field}\" size=\"{$profilefield['length']}\">$select</select>";
				}
			}

and you can see the $code variable at the bottom that's passed to the template. Unfortunately, I don't know enough php yet to figure out how to append the colon onto the field label. Very frustrating.
I might be able to compare this code against the code that builds the fields in the UCP later today. Hmm...
You are just trying to start a text box with a default value?

locate this block of code around line 60 of member.php
elseif($type == "textarea")
			{
				$value = htmlspecialchars_uni($userfield);
				$code = "<textarea name=\"profile_fields[$field]\" id=\"{$field}\" rows=\"6\" cols=\"30\" style=\"width: 95%\">$value</textarea>";
			}
			else
			{
				$value = htmlspecialchars_uni($userfield);
				$maxlength = "";
				if($profilefield['maxlength'] > 0)
				{
					$maxlength = " maxlength=\"{$profilefield['maxlength']}\"";
				}
				$code = "<input type=\"text\" name=\"profile_fields[$field]\" id=\"{$field}\" class=\"textbox\" size=\"{$profilefield['length']}\"{$maxlength} value=\"$value\" />";
			}

and then change this :
				$code = "<input type=\"text\" name=\"profile_fields[$field]\" id=\"{$field}\" class=\"textbox\" size=\"{$profilefield['length']}\"{$maxlength} value=\"$value\" />";
			
to this:

				if($field =="fid5"){
				$code = "<input type=\"text\" name=\"profile_fields[$field]\" id=\"{$field}\" class=\"textbox\" size=\"{$profilefield['length']}\"{$maxlength} value=\"My Default\" />";
				}
				else {
					$code = "<input type=\"text\" name=\"profile_fields[$field]\" id=\"{$field}\" class=\"textbox\" size=\"{$profilefield['length']}\"{$maxlength} value=\"$value\" />";
				}

In my sample code I am using "fid5" as the custom field you will have to check to see what the id of your custom field is. Them just change the words "My Default" to the value that you want.

it should be around line 600 in member.php