PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

Requiring something from a drop-down

s2Member Plugin. A Membership plugin for WordPress®.

Requiring something from a drop-down

Postby philipt18 » January 9th, 2012, 5:54 am

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.
User avatar
philipt18
Experienced User
Experienced User
 
Posts: 50
Joined: December 1, 2011

Re: Requiring something from a drop-down

Postby philipt18 » January 10th, 2012, 10:43 am

Any ideas here? Is there no way to require a drop-down menu without specifying a default value?
User avatar
philipt18
Experienced User
Experienced User
 
Posts: 50
Joined: December 1, 2011

Re: Requiring something from a drop-down

Postby philipt18 » January 11th, 2012, 1:40 pm

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
User avatar
philipt18
Experienced User
Experienced User
 
Posts: 50
Joined: December 1, 2011

Re: Requiring something from a drop-down

Postby Raam Dev » January 11th, 2012, 1:51 pm

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:

Screen shot 2012-01-11 at 13.48.01 .png
Raam Dev || Wherever you are, be there. || Please rate s2Member!
User avatar
Raam Dev
Developer
Developer
 
Posts: 810
Joined: October 26, 2011

Re: Requiring something from a drop-down

Postby philipt18 » January 11th, 2012, 2:03 pm

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.
User avatar
philipt18
Experienced User
Experienced User
 
Posts: 50
Joined: December 1, 2011

Re: Requiring something from a drop-down

Postby Raam Dev » January 11th, 2012, 2:04 pm

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!
Raam Dev || Wherever you are, be there. || Please rate s2Member!
User avatar
Raam Dev
Developer
Developer
 
Posts: 810
Joined: October 26, 2011

Re: Requiring something from a drop-down

Postby Jason Caldwell » January 15th, 2012, 12:53 am

Investigating this now.
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Requiring something from a drop-down

Postby Jason Caldwell » January 15th, 2012, 11:04 am

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.php

This file patches an existing installation of s2Member v111220.
custom-reg-fields.inc.php.zip
(4.88 KiB) Downloaded 9 times
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Requiring something from a drop-down

Postby philipt18 » January 15th, 2012, 11:09 am

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.
User avatar
philipt18
Experienced User
Experienced User
 
Posts: 50
Joined: December 1, 2011

Re: Requiring something from a drop-down

Postby Jason Caldwell » January 15th, 2012, 11:17 am

Very welcome. I'll reference your other thread here:
viewtopic.php?f=4&t=16836&p=60574#p60574
Currently investigating, and we'll continue discussion in the other thread please. Thanks!
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA


Return to s2Member Plugin

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 1 guest

cron