MyBB Community Forums

Full Version: Forcing a Select Box to be a Required Custom Profile Field
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Sorry to be a pain on a day when you guys are busy handling 1.4 upgrade issues but this is the last remaining issue to stop my BB going live.

At present, the first item in the Select Box in a custom profile field is being treated as a valid entry even though the user may not have touched it and it is wrong. Is there any way I can force the first item to be blank and therefore fail validation forcing the user to select an appropriate value?

Thanks
Gentle 'bump'. Wink

Thanks
Maybe there isn't an answer...

Maybe this should be a feature request for the next release.
Well for now, why don't you make it a radio button with 'yes/accept' and 'no/don't accept' and just have 'no/don't accept' first so that it defaults?
(2008-08-03, 07:06 PM)SteelD Wrote: [ -> ]At present, the first item in the Select Box in a custom profile field is being treated as a valid entry even though the user may not have touched it and it is wrong.

That's a good point; I think the developers should consider fixing this. If you add a new profile field after a user has registered, they might not even notice it next time they update their profile. :/

In the meantime, here's a simple code modification that should do what you want...

In usercp.php find:
elseif($type == "select")
{
	$expoptions = explode("\n", $options);
	if(is_array($expoptions))
	{

And add this underneath:
if($profilefield['required'] == 1)
{
	array_unshift($expoptions, ''); // Add a blank option
}

Make the same change to member.php for the registration form.
Its one of the options when you make/edit the field.
(2008-08-16, 08:09 AM)danrulz98 Wrote: [ -> ]Its one of the options when you make/edit the field.
Yes, that makes it into a required field, no problem there. However, the select box doesn't permit blank entries meaning that it displays the first item in the list by default and that will be treated as a valid input whether the user touches that field or not.

I will look at WDZ's solution which appears to force a blank line into the list and thus might solve the issue.
[Post amended by SteelD at 23:05]
Excellent! WDZ's solution works for me. It's great having both an excellent and customisable BB and knowledgeable users. Thanks everybody.