Results 1 to 7 of 7

Thread: Country Select Menu

  1. #1
    New user
    Join Date
    07-10-09.
    Posts
    13

    Default Country Select Menu

    I wondered if anyone had done any work creating a specific Country Select Menu for the form entry. (A lot of typing is required to do this manually obviously.) I used the html option to create a field but when using this method, the data is not returned in the notification e-mail. I thought it might be possible to use the select menu (DB) option to pull out the country names but I'm not sure how to properly insert data to the database. Any help welcomed. Thanks in advance

  2. #2
    User
    Join Date
    06-19-09.
    Posts
    106

    Default Re: Country Select Menu

    As far as I know there is nothing included in TL or any extension. There was talk about it at the old forum a while ago:
    http://www.typolight.org/forum/message/38157.html

  3. #3
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: Country Select Menu

    Good old Andreas wrote an extension for it....
    http://www.typolight.org/extension-l...000009.en.html

  4. #4
    New user
    Join Date
    07-10-09.
    Posts
    13

    Default Re: Country Select Menu

    As you say Good old Andreas - I'll check it out straightaway.

    Checked out fine: Many thanks

  5. #5
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: Country Select Menu

    Andreas, I'm hoping you might update your countryselect extension (I've made it easy for you!)
    This will add the ability to use it in the backend using
    'inputType' => 'countryselect',
    Add a CountrySelectMenu.php file
    Code:
    <?php if (!defined('TL_ROOT')) die('You can not access this file directly!');
    
    /**
     * TYPOlight webCMS
     * Copyright (C) 2005 Leo Feyer
     *
     * This program is free software: you can redistribute it and/or
     * modify it under the terms of the GNU Lesser General Public
     * License as published by the Free Software Foundation, either
     * version 2.1 of the License, or (at your option) any later version.
     * 
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
     * Lesser General Public License for more details.
     * 
     * You should have received a copy of the GNU Lesser General Public
     * License along with this program. If not, please visit the Free
     * Software Foundation website at http://www.gnu.org/licenses/.
     *
     * PHP version 5
     * @copyright  Andreas Schempp 2009
     * @author     Andreas Schempp <andreas@schempp.ch
     * @license    LGPL
     */
    
    
    class CountrySelectMenu extends SelectMenu
    {
    
    	public function __set($strKey, $varValue)
    	{
    		switch ($strKey)
    		{			
    			case 'options':
    				break;
    				
    			default:
    				parent::__set($strKey, $varValue);
    				break;
    		}
    	}
    	
    	
    	public function generate()
    	{
    		$arrOptions = array(array('label'=>'-', 'value'=>''));
    		$arrCountries = $this->getCountries();
    		
    		foreach( $arrCountries as $short => $name )
    		{
    			$arrOptions[] = array('label'=>$name, 'value'=>$short);
    		}
    		
    		$this->arrOptions = $arrOptions;
    		
    		return parent::generate();
    	}
    
    }
    And in the config.php add
    Code:
    /**
     * Backend form fields
     */
    $GLOBALS['BE_FFL']['countryselect'] = 'CountrySelectMenu';
    I'd rather you update yours if its not a hassle, rather than have two extensions in there.
    Cheers, murray

  6. #6
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: Country Select Menu

    While I'm at it, I get 'nz' (or any two letter code) returned from a table to $country in a php file.
    Can anyone help me with code to get $country to be 'New Zealand' ?
    I guess I use $this->getCountries() somehow, and match the two letter code, and draw out the long name.... but I'm a bit stuck.
    Cheers.

  7. #7
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: Country Select Menu

    Got it...

    Code:
    //Do database call
    $objJobs = $this->Database->execute("SELECT * FROM blah blah blah");
    
    //get the countries array from Typolight ONCE outside of while loop
                                   $arrCountries = $this->getCountries();
    
    //loop thru Database records returned
    		while ($objJobs->next())
    		{
    		$job_id = $objJobs->id;
    		$job_category = $objJobs->job_category;
    		$job_country = $objJobs->job_country;
    
    //TURN $job_country from 2 letter code to full name for display		
                                    $job_country = $arrCountries[$job_country];
    
    .....
    PS: Tom, Maybe this thread should be moved to "General" Extensions...its in EFG for some reason (sorry)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •