Zend Framework Forum

Go Back   Zend Framework Forum > Zend Framework General discussions > Resources for Developers

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-25-2008, 11:06 PM
Junior Member
 
Join Date: Nov 2008
Posts: 1
Default Custom Form Element tutorial wanted

Hey everyone.

I create form classes that extend Zend_Form for my models. When I want to create a form element I type
Code:
$company_name = new Zend_Form_Element_Text('company_name');
What I want to do is create a custom form element for like a phone number so I would type
Code:
$phone_number = new Kwista_Zend_Form_Element_Phone_Number('phone_number');
and when I displayed the form for that element it would show [HTML](<input type="text" size="2" name="phone_number[]">) <input type="text" size="2" name="phone_number[]"> - <input type="text" size="3" name="phone_number[]"> ext. <input type="text" size="3" name="phone_number[]">[/HTML] Are there any tutorials out there that would show me how to do this? Also I want to place it in a nice folder in my application so I can reuse it in any of my other applications.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 12-31-2008, 12:34 AM
Junior Member
 
Join Date: Dec 2008
Location: Romania
Posts: 7
Send a message via Yahoo to chisflorinel
Default Zend Form reference

See the last part of Zend Framework - Zend_Form reference
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-02-2009, 03:46 PM
Junior Member
 
Join Date: Jul 2009
Posts: 2
Default Did you solve the problem?

@cabofixe:
I'm just wondering if you solved the problem (and if; how :-D)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-28-2009, 06:02 PM
Member
 
Join Date: Jun 2009
Posts: 74
Default

I think you would need two files, My_Form_Element_Phonenumber and My_View_Helper_FormPhonenumber.

Code:
<?php

class My_Form_Element_Phonenumber extends Zend_Form_Element 
{
    public $helper = 'formPhonenumber';

    public function setValue($value)
    {  
        if(is_array($value))
        {
            @list($first, $second, $third, $ext) = $value;	
             
            // saving comma-delimited for simplicity, save however you want
            // this is NOT the display
            $value = sprintf('%s,%s,%s,%s', $first, $second, $third, $ext);
        }

        return parent::setValue($value);
    }

}
Code:
<?

require_once 'Zend/View/Helper/FormElement.php';

class My_View_Helper_Phonenumber extends Zend_View_Helper_FormElement {
    
    public function formPhonenumber($name, $value = null, $attribs = null) {
        $info = $this->_getInfo($name, $value, $attribs);
        extract($info); // name, value, attribs, options, listsep, disable

        $value=$this->view->escape($value);

        // retrieve from comma-delimited list
        list($first, second, $third, $ext) = split(',', $value);
            
        $html = '(<input type="text" size=2'
                . ' name="' . $this->view->escape($name) . '[]"'
                . ' value="' . $first . '">)'
 
        $html = ' <input type="text" size=2'
                . ' name="' . $this->view->escape($name) . '[]"'
                . ' value="' . $second . '">'

        $html = ' - <input type="text" size=3'
                . ' name="' . $this->view->escape($name) . '[]"'
                . ' value="' . $third . '">'

        $html = ' ext. <input type="text" size=3'
                . ' name="' . $this->view->escape($name) . '[]"'
                . ' value="' . $ext . '">'               

        return $html;
    }
}
This is untested, loosely based on some of my working code.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT. The time now is 12:32 AM.


Designed by: Miner Skinz Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0