The Techjoomla Blog

Stay updated with all the latest happenings at Techjoomla. From news about the developments in your favourite extensions to Tips & Tricks about the Joomla CMS, Framework & Development.
Font size: +
1 minute reading time (202 words)

Zoo - Creating an address field element

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.

    Address
    Tekdi
    Feb 2013
    Copyright (C) tekdi
    
    http://www.tekdi.net
    1.0.0
    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 

3
×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

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

Related Posts

 

Blog Topics