Cnz_Html
[
class tree: Cnz_Html
] [
index: Cnz_Html
] [
all elements
]
Todo List
Packages:
Cnz
Cnz_Html
Source for file Abstract.php
Documentation is available at
Abstract.php
<?php
/**
* CNZ Framework
*
* A Framework for Creating and Using Complex Web Elements
*
* The purpose of this framework is to provide a library of high-level objects
* to facilitate common HTML coding tasks, such as menus, tables, and forms.
* The intent is to reduce repetitive HTML coding as much as possible, replacing
* it with a combination of configuration files and style sheets with
* standardized naming conventions.
*
* This framework is built on and requires the
*
{@link http://framework.zend.com/ Zend Framework}
.
*
*
@category
Cnz
*
@package
Cnz_Html
*
@subpackage
Form
*
*
@author
Lyle Frost <lfrost@cnz.com>
*
@copyright
Copyright (c) 2006-2007 Citadel Network <
{@link http://www.citadelnetwork.com/}
>
*
@filesource
*
@license
http://www.citadelnetwork.com/license/cnzframework New BSD License
*
@version
$Id: Abstract.php 27 2007-07-19 18:47:54Z lfrost $
*/
/**
* Required classes.
*
*
@ignore
*/
Zend_Loader
::
loadClass
(
'Cnz_Html_Element'
)
;
Zend_Loader
::
loadClass
(
'Cnz_Html_Form_Checkbox'
)
;
Zend_Loader
::
loadClass
(
'Cnz_Html_Form_File'
)
;
Zend_Loader
::
loadClass
(
'Cnz_Html_Form_Group'
)
;
Zend_Loader
::
loadClass
(
'Cnz_Html_Form_Hidden'
)
;
Zend_Loader
::
loadClass
(
'Cnz_Html_Form_Password'
)
;
Zend_Loader
::
loadClass
(
'Cnz_Html_Form_Radio'
)
;
Zend_Loader
::
loadClass
(
'Cnz_Html_Form_Select'
)
;
Zend_Loader
::
loadClass
(
'Cnz_Html_Form_Text'
)
;
Zend_Loader
::
loadClass
(
'Cnz_Html_Form_Textarea'
)
;
/**
* HTML Form Abstract class
*
* Abstract base class for forms.
*
*
@category
Cnz
*
@package
Cnz_Html
*
@subpackage
Form
*/
abstract
class
Cnz_Html_Form_Abstract
extends
Cnz_Html_Element
{
const
HAS_CONFIG
=
true
;
/**#@+ @var array */
private
$data
=
NULL
;
private
$defaultArray
=
array
(
)
;
private
$itemArray
=
NULL
;
/**#@-*/
/**#@+ @var boolean */
protected
$fileFlag
=
false
;
/**#@-*/
/**
@var
Zend_Db_Table_Row_Abstract
*/
protected
$row
=
NULL
;
/* Methods ===========================================================*/
/**
* Option fields:
* default Associative array containing default field values
* row Zend_Db_Table_Row containing data for this form
*
*
@param
array
$options
Options
*
@param
Zend_Config
$config
Configuration
*/
public
function
__construct
(
array
$options
=
array
(
))
{
parent
::
__construct
(
$options
)
;
if
(
isset
(
$options
[
'default'
]
))
$this
->
defaultArray
=
$options
[
'default'
]
;
if
(
isset
(
$options
[
'row'
]
))
$this
->
row
=
$options
[
'row'
]
;
// Create items.
$i
=
0
;
if
(
isset
(
$this
->
config
->
item
))
{
for
(
$this
->
config
->
item
->
rewind
(
)
;
$this
->
config
->
item
->
valid
(
)
;
$this
->
config
->
item
->
next
(
))
{
$type
=
ucfirst
(
strtolower
(
$this
->
config
->
item
->
current
(
)
->
type
))
;
if
(
$type
==
'File'
)
$this
->
fileFlag
=
true
;
$className
=
'Cnz_Html_Form_'
.
$type
;
$options
[
'name'
]
=
$this
->
config
->
item
->
key
(
)
;
if
(
isset
(
$this
->
defaultArray
[
$options
[
'name'
]]
))
{
$options
[
'initial'
]
=
$this
->
defaultArray
[
$options
[
'name'
]]
;
}
elseif
(
is_object
(
$this
->
row
)
&& isset
(
$this
->
row
->
$options
[
'name'
]
))
{
$options
[
'initial'
]
=
$this
->
row
->
$options
[
'name'
]
;
}
else
unset
(
$options
[
'initial'
]
)
;
$this
->
itemArray
[
$i
]
=
new
$className
(
$options
,
$this
->
config
->
item
->
current
(
))
;
if
(
$this
->
itemArray
[
$i
]
instanceof
$this
)
{
if
(
$this
->
itemArray
[
$i
]
.
hasFile
(
))
$this
->
fileFlag
=
true
;
}
$i
++
;
}
}
return
;
}
/**
*
@return
boolean
Has a file field
*/
public
function
hasFile
(
)
{
return
$this
->
fileFlag
;
}
/**
*
@param
string
$style
Value for outermost style attribute
*
@return
void
*/
public
function
display
(
$style
=
NULL
)
{
$count
=
count
(
$this
->
itemArray
)
;
for
(
$i
=
0
;
$i
<
$count
;
$i
++
)
{
$this
->
itemArray
[
$i
]
->
display
(
$style
)
;
// IE hack
if
(
!
Cnz_Html
::
isXhtml
(
)
&&
!
$this
->
itemArray
[
$i
]
instanceof
Cnz_Html_Form_Hidden
)
echo
'<br>'
;
}
return
;
}
/**
* This function returns a string formatted for display or submission by
* mail.
*
*
@param
array
$data
Form data
*
@return
string
*/
public
function
submitString
(
array
$data
=
NULL
)
{
$result
=
''
;
$count
=
count
(
$this
->
itemArray
)
;
for
(
$i
=
0
;
$i
<
$count
;
$i
++
)
{
$result
.=
$this
->
itemArray
[
$i
]
->
submitString
(
$data
)
;
}
return
$result
;
}
}
Documentation generated on Thu, 19 Jul 2007 15:01:55 -0400 by
phpDocumentor 1.4.0RC2