Page 1 of 1
Requiring something from a drop-down
Posted:
January 9th, 2012, 5:54 am
by philipt18
I'm looking to require the user to select a country during registration. I have a country list in a drop-down. Originally I added a default country, but people are lazy and leave that country checked even if they live in a different country. So I want to have no country selected and make them choose one from the list. I tried to make a NULL value the default, but apparently NULL is accepted as a value. How do I set it up so the country is required, but nothing is selected?
Thank you.
Re: Requiring something from a drop-down
Posted:
January 10th, 2012, 10:43 am
by philipt18
Any ideas here? Is there no way to require a drop-down menu without specifying a default value?
Re: Requiring something from a drop-down
Posted:
January 11th, 2012, 1:40 pm
by philipt18
So I figured out a way to do this, but I also found a bug. It turns out that while !NULL is recognized as a value, leaving nothing there and just starting with a pipe works to create a value that is not accepted. Thus, I was able to do:
|--Select a Country--|default
US|United States
CA|Canada
...etc...
That worked. Then I tried to do something similar for states and provinces. As I don't have a way to require the state/province only if the user has selected US or Canada, I have to leave the state/province field as optional. I created a piped list of US States and Canadian provinces (reproduced in full below). Even though I added the default tag to the first line which told people to select an option (similar to the Country menu above which worked fine), it never selected that as the default. Instead, the system always selected the non-selectable line I inserted above the provinces:
|--Canada--
Why was this line selected? I have no idea. No matter what I tried, it always selected that line. As a temporary fix I removed the lines indicating United States and Canada, and just merged the two lists into a single list. Seems to be a bug. The full piped list was:
|--Please Select--|default
|--United States--
AL|Alabama
AK|Alaska
AZ|Arizona
AR|Arkansas
CA|California
CO|Colorado
CT|Connecticut
DE|Delaware
DC|District Of Columbia
FL|Florida
GA|Georgia
HI|Hawaii
ID|Idaho
IL|Illinois
IN|Indiana
IA|Iowa
KS|Kansas
KY|Kentucky
LA|Louisiana
ME|Maine
MD|Maryland
MA|Massachusetts
MI|Michigan
MN|Minnesota
MS|Mississippi
MO|Missouri
MT|Montana
NE|Nebraska
NV|Nevada
NH|New Hampshire
NJ|New Jersey
NM|New Mexico
NY|New York
NC|North Carolina
ND|North Dakota
OH|Ohio
OK|Oklahoma
OR|Oregon
PA|Pennsylvania
RI|Rhode Island
SC|South Carolina
SD|South Dakota
TN|Tennessee
TX|Texas
UT|Utah
VT|Vermont
VA|Virginia
WA|Washington
WV|West Virginia
WI|Wisconsin
WY|Wyoming
|--Canada--
AB|Alberta
BC|British Columbia
MB|Manitoba
NB|New Brunswick
NL|Newfoundland and Labrador
NS|Nova Scotia
NT|Northwest Territories
NU|Nunavut
ON|Ontario
PE|Prince Edward Island
QC|Quebec
SK|Saskatchewan
YT|Yukon
Re: Requiring something from a drop-down
Posted:
January 11th, 2012, 1:51 pm
by Raam Dev
You can do this by making the select field required (
Field Required: * = Yes ( required )) and then making your first item have a blank value (the item before the first separator):
|Please select one...|default
US|United States
CA|Canada
VI|Virgin Islands (U.S.)
I tested this and when I fill out my registration form leaving the country on "Please select one...", and then press submit, here's what I get:
Re: Requiring something from a drop-down
Posted:
January 11th, 2012, 2:03 pm
by philipt18
As I explained, that's exactly what I did. However, it seems there is a bug in selecting the default value in the list I provided.
Re: Requiring something from a drop-down
Posted:
January 11th, 2012, 2:04 pm
by Raam Dev
I recreated the bug. That's interesting. Looking at the HTML source, it shows that all of the lines with an empty value (i.e., what goes before the first separator) automatically get the
selected="selected" attribute added:
- Code: Select all
<select name="ws_plugin__s2member_custom_reg_field_country" id="ws-plugin--s2member-custom-reg-field-country" aria-required="true" tabindex="50" class="ws-plugin--s2member-custom-reg-field">
<option value="" selected="selected">--Please Select--</option>
<option value="" selected="selected">--United States--</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
...
<option value="" select="selected">--Canada--</option>
<option value="AB">Alberta</option>
<option value="BC">British Columbia</option>
...
</select>
The browser is simply using the last
selected="selected" item as the default (in this case, Canada).
I will report this to the development team and see if they know what's going on.
Thank you for your patience!
Re: Requiring something from a drop-down
Posted:
January 15th, 2012, 12:53 am
by Jason Caldwell
Investigating this now.
Re: Requiring something from a drop-down
Posted:
January 15th, 2012, 11:04 am
by Jason Caldwell
Thanks for your patience.Yes, this is a bug. I'm having this corrected in the next maintenance release. Until then, you can get ahead in the game if you like, by downloading the attached patch file. Unzip and upload this file, allowing it override your existing copy of
/s2member/includes/classes/custom-reg-fields.inc.phpThis file patches an existing installation of s2Member v111220.
Re: Requiring something from a drop-down
Posted:
January 15th, 2012, 11:09 am
by philipt18
Great Jason, thank you. I hope you will also look at the other bug I posted about, where admins who edit users have some custom fields that are menus reset when editing.
Re: Requiring something from a drop-down
Posted:
January 15th, 2012, 11:17 am
by Jason Caldwell
Very welcome. I'll reference your other thread here:
viewtopic.php?f=4&t=16836&p=60574#p60574Currently investigating, and we'll continue discussion in the other thread please. Thanks!