I am using phpList v3.2.6.
When creating a subscription (subscribe) sign-up page:
- using a SELECT attribute
- marking is as not required
… the subscription page will display / default to the first item of the attribute, instead of a blank or unselected. Also, once an item in select there is no way to unselect this attribute.
@LeftPinkie See this section from config_extended.php
// empty value prefix. This can be used to identify values in select attributes
// that are not allowed to be selected and cause an error "Please enter your ..."
// by using a top value that starts with this string, you can make sure that the
// selects do not have a default value, that may be accidentally selected
// eg. "-- choose your country"
You need to add another value to your select attribute that begins with “–” and make it the first to be displayed.
Don’t forget to add the above to your config.php file.
Actually I can add a default value in the admin page under Configu => Subscribe pages => Edit
add the following line to my config.php file:
define( 'EMPTY_VALUE_PREFIX' , '--' ) ;
Either method I still need to add a record to my database table
listattr_... and the record’s
name has to match my default value. Thank you @duncanc for this reminder.
That solves my initial question but leads me to another question / dilemma…
The select attribute I am offering is a list of countries. I am using the ISO 3166-1 country code list and importing it into my table
listattr_country, with the ISO-3166-1 numeric code as the record
id. So when I go and add a record for the default value, I am giving it a record
id of 0. I need this record
id to be 0 so that I can query if a valid country was selected. Since the column
id is the primary key, any DBA will tell you it is bad to have the
id of 0. MySQL will complain if I do a table integrity check. I guess I could give it some ridiculously high record
id so ISO-3166 would never reach in the future. Or, I could modify the phpList code so that default value is not inserted into the database… but then I won’t be compatible with future upgrades.
@LeftPinkie You seem to be confusing having a default value with not entering a value at all. phplist uses the EMPTY_VALUE_PREFIX to decide whether a value has been selected or not. Then what happens depends on whether the attribute is required or not.
If I set
EMPTY_VALUE_PREFIX without a valid record of the same
name in my database table, the first value shows up on the selection not the empty value. Are you saying that if I set the
EMPTY_VALUE_PREFIX and have a matching record in the database and set the attribute to not required, then the app will not insert this attribute?
@LeftPinkie More or less. I suggest that you try this out for yourself to see how it works.