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
Hi,
I'm using MyBB 1.6.8.
I have 5 mandatory custom fields but always the first item is selected as default in registration page, so users can bypass it without choosing any item. How can I set a blank item as default to make users to choose an item from list?
If I insert a blank item in its option, MyBB removes that blank item and the first non-blank item will be replaced.
Thanks
I've added a security question to all registrations. You can do this in a plugin but I've been lazy and made the changes to source files.

Before the new user is added to the database, add a bit of code like this
if ($mybb->input['requiredfield'] == '') {
$errors[] = 'You didn't do this!';
}

Make sure you add a new error like elsewhere in that area, so that MyBB will find your error and prevent the registration (and output your error with any other errors).

If you open member.php and search for $db->insert you'll find the code that adds the new user. Either write a plugin to hook into there, or make some changes to error if the user hasn't filled this in.

As for an empty field just use a - symbol or something to indicate it's empty.
No no. this method is like spam registration prevention. I don't need that.
I want to force users to input accurate and correct data to categorize them.

My forum is for students and one of registration fields is their major. They should select their major from a dropdown list. currently they can ignore choosing correct answer because thee default option is selected and they are not forced to change it's value.
(2012-07-05, 08:34 AM)armin3000 Wrote: [ -> ]No no. this method is like spam registration prevention. I don't need that.
I want to force users to input accurate and correct data to categorize them.

My forum is for students and one of registration fields is their major. They should select their major from a dropdown list. currently they can ignore choosing correct answer because thee default option is selected and they are not forced to change it's value.

My method of spam prevention can be applied to your request. You just need to make sure your IF statement catches anything you don't want. If you don't want your users selecting an empty option, do this:

if ($mybb->input['category'] == '') {
//error...
}

You could get a bit more complex with having an array of possible values they could choose. I recommend not doing this in favour of MyBB's own way of having a list of possible ways, but doing it your own way has its benefits.

$majors = array('medicine', 'maths', 'history');

if ($mybb->input['major'] != in_array($majors)) {
//error...
}
Instead of blank try using .....? so the user would know they are being asked a choice.
Make it mandatory to fill custom field from ACP
(2012-07-06, 06:09 AM)ranjan2001 Wrote: [ -> ]Instead of blank try using .....? so the user would know they are being asked a choice.
Make it mandatory to fill custom field from ACP

An option with ...... won't say anything. Maybe make it obvious with all caps REQUIRED so that they'll notice it and fill it out.

Forcing the issue with a little bit of programming would be best though. It'll save you cleaning up mistakes later.
(2012-07-06, 05:45 AM)Jazza Wrote: [ -> ]
(2012-07-05, 08:34 AM)armin3000 Wrote: [ -> ]No no. this method is like spam registration prevention. I don't need that.
I want to force users to input accurate and correct data to categorize them.

My forum is for students and one of registration fields is their major. They should select their major from a dropdown list. currently they can ignore choosing correct answer because thee default option is selected and they are not forced to change it's value.

My method of spam prevention can be applied to your request. You just need to make sure your IF statement catches anything you don't want. If you don't want your users selecting an empty option, do this:

if ($mybb->input['category'] == '') {
//error...
}

You could get a bit more complex with having an array of possible values they could choose. I recommend not doing this in favour of MyBB's own way of having a list of possible ways, but doing it your own way has its benefits.

$majors = array('medicine', 'maths', 'history');

if ($mybb->input['major'] != in_array($majors)) {
//error...
}

Thanks. I understand what you mean. In member.php file I only found these "$db->insert" string, I don't think so that they are related to what you said:

$db->insert_query("awaitingactivation", $activationarray);
$db->insert_query("awaitingactivation", $awaitingarray);
$db->insert_query("awaitingactivation", $awaitingarray);
$db->insert_query("captcha", $imagearray);
$db->insert_query("maillogs", $log_entry);

where exactly I have to insert that code?
I have created 3 custom fields (for example fid1,fid2,fid3), they are "select list boxes". First item for each of them is "-".
What next?

Sorry if I ask simple questions in programming, I'm not a PHP programmer.

Thank you

(2012-07-06, 06:09 AM)ranjan2001 Wrote: [ -> ]Instead of blank try using .....? so the user would know they are being asked a choice.
Make it mandatory to fill custom field from ACP

They can easily leave the default item "...." and mybb will verify this answer!! It doesn't mean mandatory. right?
It's okay, we're not all PHP programmers. I tend to assume that anyone who posts here is. At least you tried to find what I was talking about.

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.
(2012-07-06, 06:25 AM)Jazza Wrote: [ -> ]
$errors[] = 'You didn't do this!';

That'll throw an error, I think you will find... Or it just won't show all the error
(2012-07-06, 06:31 AM)bcousins Wrote: [ -> ]
(2012-07-06, 06:25 AM)Jazza Wrote: [ -> ]
$errors[] = 'You didn't do this!';

That'll throw an error, I think you will find... Or it just won't show all the error

It will add a new entry to the predefined array of errors. MyBB then checks if there are any entries in the array and if so, won't add the new user and will return to the registration form with all error messages.
Pages: 1 2