• Resolved Haste

    (@haste18)


    Hi,

    I want to ask users to select their timezone and I’m trying to use the select field for this.

    The problem I’ve got is that I want to show them a list with GMT times, but store the location/city inside the database.

    ie.

    ‘(GMT-12:00) International Date Line West’ => ‘Pacific/Wake’,
    ‘(GMT-11:00) Midway Island’ => ‘Pacific/Apia’,
    ‘(GMT-11:00) Samoa’ => ‘Pacific/Apia’,
    ‘(GMT-10:00) Hawaii’ => ‘Pacific/Honolulu’,
    ….

    I’ve tried modifying the class of select field to put the timezones in an array. It shows all the values, but it doesn’t stores the same value shown in the list in the database.

    	public function __construct() {
    
    		$this->id                       = 'user_registration_select';
    		$this->form_id                  = 1;
    		$this->registered_fields_config = array(
    			'label' => __( 'Select', 'user-registration' ),
    			'icon'  => 'ur-icon ur-icon-drop-down',
    		);
    
    		$this->field_defaults = array(
    			'default_label'      => __( 'Select', 'user-registration' ),
    			'default_field_name' => 'select_' . ur_get_random_number(),
    			'default_options'    => array(
    				'Pacific/Midway'       => __( '(GMT-11:00) Midway Island', 'user-registration' ),
    				'US/Samoa'             => __( '(GMT-11:00) Samoa', 'user-registration' ),
    				'US/Hawaii'            => __( '(GMT-10:00) Hawaii', 'user-registration' ),
    				'US/Alaska'            => __( '(GMT-09:00) Alaska', 'user-registration' ),
    				'US/Pacific'           => __( '(GMT-08:00) Pacific Time (US & Canada)', 'user-registration' ),
    				'America/Tijuana'      => __( '(GMT-08:00) Tijuana', 'user-registration' ),

    Is there any way to fix this? I see it’s working for countries where Afghanistan stores the value AF, etc.

    Thanks!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘How to use select field with option value?’ is closed to new replies.