1 minute reading time (202 words)

Zoo - Creating an address field element


Here's a short tutorial on creating a Zoo element that has multiple sub-fields. A good example for the same, which we've also used as a sample is an address field. An address field will typically have different parts such as city, zip, state etc. I assume you have already gone through the zoo documentation on creating a new custom element - http://www.yootheme.com/zoo/documentation/developers/create-a-custom-element

Step 1: The XML file
create the media/zoo/applications//elements/address/address.xml file.

    Feb 2013
    Copyright (C) tekdi
    Repeateble city,country and state fields

Step 2: The PHP file
create this file: media/zoo/applications//elements/address/address.php

loader->register('ElementRepeatable', 'elements:repeatable/repeatable.php');
class ElementAddress extends ElementRepeatable implements iRepeatSubmittable {
    protected function _hasValue($params = array()) {
        $value = $this->get('value');
        return $this->_containsEmail($value);
    public function getText() {
        $text = $this->get('value', '');
        return empty($text) ? $this->get('value', '') : $text;
    protected function _edit(){
        return $this->_editForm();
    public function _renderSubmission($params = array()) {
        return $this->_editForm($params->get('trusted_mode'));
    protected function _editForm($trusted_mode = true) {
        if ($layout = $this->getLayout('edit.php')) {
            return $this->renderLayout($layout,
                array('trusted_mode' => $trusted_mode
    public function _validateSubmission($value, $params) {
        $values    = $value;
        $validator = $this->app->validator->create('string', array('required' => false));
        $value      = $validator->clean($values->get('value'));
        $country   = $validator->clean($values->get('country'));
        $state      = $validator->clean($values->get('state'));
        return compact( 'value', 'country', 'state');

Step 3: Another PHP file
create this file: media/zoo/applications//elements/address/tmpl/edit.php 

Invitex ver 2.7 is here with Joomla 3.X support !
Easter Sale!!

Related Posts


By accepting you will be accessing a service provided by a third-party external to https://techjoomla.com/

Blog Topics