2017 © Pedro Peláez
 

library country-field

Country select field localized for every single language. It is intended to be used in ATK14 Forms.

image

atk14/country-field

Country select field localized for every single language. It is intended to be used in ATK14 Forms.

  • Friday, February 2, 2018
  • by yarri
  • Repository
  • 2 Watchers
  • 0 Stars
  • 105 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

CountryField

Build Status, (*1)

Country select field localized for every single language. It is intended to be used in ATK14 Forms., (*2)

It uses https://github.com/umpirsky/country-list as the localized countries list., (*3)

It also contains Smarty modifier which displays the country name according to its code ISO., (*4)

Basic usage

In a form:, (*5)

<?php
// file: app/forms/users/create_new_form.php
class CreateNewForm extends ApplicationForm {

  function set_up(){
    $this->add_field("name", new CharField([
      "label" => "Your name",
      "hint" => "John Doe"
    ]));

    // other fields...

    $this->add_field("country_code", new CountryField([
      "label" => "Choose your country",
      "initial" => "CZ"
    ]));
  }
}

In a template:, (*6)

{*
 * file: app/views/users/detail.tpl
 *}

 <h1>{t}Your personal data{/t}</h1>

 <h3>{t}Address{/t}</h3>

 {t}Country:{/t} {$user->getCountryCode()|to_country_name}

Special cases

It's possible to define a limited set of countries., (*7)

$this->add_field("country_code", new CountryField([
  "label" => "Choose your favourite V4 country",
  "allowed_countries" => ["CZ","SK","PL","HU"]
]));

It's also possible to define list of countries which are not allowed., (*8)

$this->add_field("country_code", new CountryField([
  "label" => "Choose country",
  "disallowed_countries" => ["BZ","IO","CF"]
]));

A title of the empty choice can be set with option empty_choice_text:, (*9)

    $this->add_field("country_code", new CountryField([
        "empty_choice_text" => "-- select country --"
    ]));

The empty choice can be omitted with option include_empty_choice:, (*10)

    $this->add_field("country_code", new CountryField([
        "include_empty_choice" => false
    ]));

Installation

Just use the Composer:, (*11)

cd path/to/your/atk14/project/
composer require atk14/country-field

ln -s ../../vendor/atk14/country-field/src/app/fields/country_field.php app/fields/country_field.php
ln -s ../../vendor/atk14/country-field/src/app/helpers/modifier.to_country_name.php app/helpers/modifier.to_country_name.php

License

CountryField is free software distributed under the terms of the MIT license, (*12)

The Versions

02/02 2018

dev-master

9999999-dev https://github.com/atk14/CountryField

Country select field localized for every single language. It is intended to be used in ATK14 Forms.

  Sources   Download

MIT

The Requires

 

The Development Requires

field forms country atk14 localized