MyBB Community Forums

Full Version: How force user to make a selection in "Select box" custom field?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(2012-07-06, 06:25 AM)Jazza Wrote: [ -> ]I digged up my member.php file and here's what you can paste:

if ($mybb->input['inputID']) {
		if ($mybb->input['inputID'] != 'degee') {
			$errors[] = 'You did not fill it out correctly';
		}
	} else {
		$errors[] = 'Please fill out everything';
	}
(replace inputID with the name of the form element - you can find this if you view source of the registration page or open your templates)

Add it before

if(is_array($errors))
(on line 192)

What it does is it first checks if it's actually been set. If yes, it then checks if it matches whatever you want it to match. If either of these steps fails, it adds a new error. Before processing the new user, it checks if there are any errors and if yes, displays them as normal.

Before trying your code, would you please check lines 663-774 (member.php, mybb 1.6.8)
			if($profilefield['required'] == 1)
			{
				// JS validator extra
				if($type == "checkbox" || $type == "radio")
				{
					$id = "{$field}0";
				}
				else
				{
					$id = "fid{$profilefield['fid']}";
				}
				$validator_extra .= "\tregValidator.register('{$id}', 'notEmpty', {failure_message:'{$lang->js_validator_not_empty}'});\n";
				
				eval("\$requiredfields .= \"".$templates->get("member_register_customfield")."\";");
			}
			$code = '';
			$select = '';
			$val = '';
			$options = '';
			$expoptions = '';
			$useropts = '';
			$seloptions = '';
		}
		if($requiredfields)
		{
			eval("\$requiredfields = \"".$templates->get("member_register_requiredfields")."\";");
		}
		if(!$fromreg)
		{
			$allownoticescheck = "checked=\"checked\"";
			$hideemailcheck = '';
			$emailnotifycheck = '';
			$receivepmscheck = "checked=\"checked\"";
			$pmnoticecheck = " checked=\"checked\"";
			$emailpmnotifycheck = '';
			$invisiblecheck = '';
			if($mybb->settings['dstcorrection'] == 1)
			{
				$enabledstcheck = "checked=\"checked\"";
			}
			
		}

isn't related?
I set the default item in dropdown "select box" to "-----" and users have to change it and select another item.
It's not related to this. Those fields are default/system ones that you shouldn't change.

What we're doing is adding extra functionality. An extra check, just before it happens. It's why it's typically a plugin (but cbf).
If you select that in the admin cp the custom field is mandatory the user that make the registration is obliged to write something in the custom field
(2012-07-06, 08:30 AM)Dominic Wrote: [ -> ]If you select that in the admin cp the custom field is mandatory the user that make the registration is obliged to write something in the custom field

This setting only works for text fields not select boxes.
(2012-07-06, 10:12 AM)armin3000 Wrote: [ -> ]
(2012-07-06, 08:30 AM)Dominic Wrote: [ -> ]If you select that in the admin cp the custom field is mandatory the user that make the registration is obliged to write something in the custom field

This setting only works for text fields not select boxes.

Exactly. I've ran into the same issue with a "state" select box. I can't have an empty one 'cause I want people to fill out their state, but people often overlook it. It's not urgent they set the correct state, but it is nice.
How can I use this in NEWREPLY and when posting NEW Threads?

I need to know how to do this from scratch for example this is what I currently have in NEWREPLY and it does not work, or return an error:

Where do the php code go and how I can make this code 'required': I am not great at code so a walk through is needed.

<td class="trow1"><strong>Check The Box</strong></td>
<td class="trow1"><script type="text/javascript">
function validateForm()
{
var x=document.forms["myForm"]["fname"].value;
if (x==null || x=="")
  {
  alert("Type a letter to say you are not a spammer!");
  return false;
  }
}
</script>
<form name="myForm" action="demo_form.asp" onsubmit="return validateForm()" method="post">
Type any letter here to state you are not a Spammer: <input type="text" name="fname">
<input type="submit" value="Reply to Post">
Sorry I don't have any experience with that. Your best bet is to follow the lead with the current spam prevention system.

Turn on posting permission for guests for a forum and try posting a thread. There should be some kind of text field to validate your human-ness. Open the source of the page or the template (not sure where it is) and try duplicating it (but rename it).

Edit: I wouldn't rely on JavaScript to validate users. People and bots can simply disable JavaScript or delete your script to get past it. Make sure your PHP validates user input too.
Pages: 1 2