Subversion Repositories Applications.papyrus

Rev

Rev 320 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 320 Rev 443
1
<?php
1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4: */
2
/* vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +----------------------------------------------------------------------+
3
// +----------------------------------------------------------------------+
4
// | PHP version 4.0                                                      |
4
// | PHP version 4.0                                                      |
5
// +----------------------------------------------------------------------+
5
// +----------------------------------------------------------------------+
6
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group             |
6
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group             |
7
// +----------------------------------------------------------------------+
7
// +----------------------------------------------------------------------+
8
// | This source file is subject to version 2.0 of the PHP license,       |
8
// | This source file is subject to version 2.0 of the PHP license,       |
9
// | that is bundled with this package in the file LICENSE, and is        |
9
// | that is bundled with this package in the file LICENSE, and is        |
10
// | available at through the world-wide-web at                           |
10
// | available at through the world-wide-web at                           |
11
// | http://www.php.net/license/2_02.txt.                                 |
11
// | http://www.php.net/license/2_02.txt.                                 |
12
// | If you did not receive a copy of the PHP license and are unable to   |
12
// | If you did not receive a copy of the PHP license and are unable to   |
13
// | obtain it through the world-wide-web, please send a note to          |
13
// | obtain it through the world-wide-web, please send a note to          |
14
// | license@php.net so we can mail you a copy immediately.               |
14
// | license@php.net so we can mail you a copy immediately.               |
15
// +----------------------------------------------------------------------+
15
// +----------------------------------------------------------------------+
16
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com>                        |
16
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com>                        |
17
// |          Bertrand Mansion <bmansion@mamasam.com>                     |
17
// |          Bertrand Mansion <bmansion@mamasam.com>                     |
18
// +----------------------------------------------------------------------+
18
// +----------------------------------------------------------------------+
19
//
19
//
20
// $Id: element.php,v 1.1 2005-03-30 08:50:33 jpm Exp $
20
// $Id: element.php,v 1.2 2005-09-20 17:01:22 ddelon Exp $
21
 
21
 
22
require_once('HTML/Common.php');
22
require_once('HTML/Common.php');
23
 
23
 
24
/**
24
/**
25
 * Base class for form elements
25
 * Base class for form elements
26
 * 
26
 * 
27
 * @author       Adam Daniel <adaniel1@eesus.jnj.com>
27
 * @author       Adam Daniel <adaniel1@eesus.jnj.com>
28
 * @author       Bertrand Mansion <bmansion@mamasam.com>
28
 * @author       Bertrand Mansion <bmansion@mamasam.com>
29
 * @version      1.3
29
 * @version      1.3
30
 * @since        PHP4.04pl1
30
 * @since        PHP4.04pl1
31
 * @access       public
31
 * @access       public
32
 * @abstract
32
 * @abstract
33
 */
33
 */
34
class HTML_QuickForm_element extends HTML_Common
34
class HTML_QuickForm_element extends HTML_Common
35
{
35
{
36
    // {{{ properties
36
    // {{{ properties
37
 
37
 
38
    /**
38
    /**
39
     * Label of the field
39
     * Label of the field
40
     * @var       string
40
     * @var       string
41
     * @since     1.3
41
     * @since     1.3
42
     * @access    private
42
     * @access    private
43
     */
43
     */
44
    var $_label = '';
44
    var $_label = '';
45
 
45
 
46
    /**
46
    /**
47
     * Form element type
47
     * Form element type
48
     * @var       string
48
     * @var       string
49
     * @since     1.0
49
     * @since     1.0
50
     * @access    private
50
     * @access    private
51
     */
51
     */
52
    var $_type = '';
52
    var $_type = '';
53
 
53
 
54
    /**
54
    /**
55
     * Flag to tell if element is frozen
55
     * Flag to tell if element is frozen
56
     * @var       boolean
56
     * @var       boolean
57
     * @since     1.0
57
     * @since     1.0
58
     * @access    private
58
     * @access    private
59
     */
59
     */
60
    var $_flagFrozen = false;
60
    var $_flagFrozen = false;
61
 
61
 
62
    /**
62
    /**
63
     * Does the element support persistant data when frozen
63
     * Does the element support persistant data when frozen
64
     * @var       boolean
64
     * @var       boolean
65
     * @since     1.3
65
     * @since     1.3
66
     * @access    private
66
     * @access    private
67
     */
67
     */
68
    var $_persistantFreeze = false;
68
    var $_persistantFreeze = false;
69
    
69
    
70
    // }}}
70
    // }}}
71
    // {{{ constructor
71
    // {{{ constructor
72
    
72
    
73
    /**
73
    /**
74
     * Class constructor
74
     * Class constructor
75
     * 
75
     * 
76
     * @param    string     Name of the element
76
     * @param    string     Name of the element
77
     * @param    mixed      Label(s) for the element
77
     * @param    mixed      Label(s) for the element
78
     * @param    mixed      Associative array of tag attributes or HTML attributes name="value" pairs
78
     * @param    mixed      Associative array of tag attributes or HTML attributes name="value" pairs
79
     * @since     1.0
79
     * @since     1.0
80
     * @access    public
80
     * @access    public
81
     * @return    void
81
     * @return    void
82
     */
82
     */
83
    function HTML_QuickForm_element($elementName=null, $elementLabel=null, $attributes=null)
83
    function HTML_QuickForm_element($elementName=null, $elementLabel=null, $attributes=null)
84
    {
84
    {
85
        HTML_Common::HTML_Common($attributes);
85
        HTML_Common::HTML_Common($attributes);
86
        if (isset($elementName)) {
86
        if (isset($elementName)) {
87
            $this->setName($elementName);
87
            $this->setName($elementName);
88
        }
88
        }
89
        if (isset($elementLabel)) {
89
        if (isset($elementLabel)) {
90
            $this->setLabel($elementLabel);
90
            $this->setLabel($elementLabel);
91
        }
91
        }
92
    } //end constructor
92
    } //end constructor
93
    
93
    
94
    // }}}
94
    // }}}
95
    // {{{ apiVersion()
95
    // {{{ apiVersion()
96
 
96
 
97
    /**
97
    /**
98
     * Returns the current API version
98
     * Returns the current API version
99
     *
99
     *
100
     * @since     1.0
100
     * @since     1.0
101
     * @access    public
101
     * @access    public
102
     * @return    float
102
     * @return    float
103
     */
103
     */
104
    function apiVersion()
104
    function apiVersion()
105
    {
105
    {
106
        return 2.0;
106
        return 2.0;
107
    } // end func apiVersion
107
    } // end func apiVersion
108
 
108
 
109
    // }}}
109
    // }}}
110
    // {{{ getType()
110
    // {{{ getType()
111
 
111
 
112
    /**
112
    /**
113
     * Returns element type
113
     * Returns element type
114
     *
114
     *
115
     * @since     1.0
115
     * @since     1.0
116
     * @access    public
116
     * @access    public
117
     * @return    string
117
     * @return    string
118
     */
118
     */
119
    function getType()
119
    function getType()
120
    {
120
    {
121
        return $this->_type;
121
        return $this->_type;
122
    } // end func getType
122
    } // end func getType
123
 
123
 
124
    // }}}
124
    // }}}
125
    // {{{ setName()
125
    // {{{ setName()
126
 
126
 
127
    /**
127
    /**
128
     * Sets the input field name
128
     * Sets the input field name
129
     * 
129
     * 
130
     * @param     string    $name   Input field name attribute
130
     * @param     string    $name   Input field name attribute
131
     * @since     1.0
131
     * @since     1.0
132
     * @access    public
132
     * @access    public
133
     * @return    void
133
     * @return    void
134
     */
134
     */
135
    function setName($name)
135
    function setName($name)
136
    {
136
    {
137
        // interface method
137
        // interface method
138
    } //end func setName
138
    } //end func setName
139
    
139
    
140
    // }}}
140
    // }}}
141
    // {{{ getName()
141
    // {{{ getName()
142
 
142
 
143
    /**
143
    /**
144
     * Returns the element name
144
     * Returns the element name
145
     * 
145
     * 
146
     * @since     1.0
146
     * @since     1.0
147
     * @access    public
147
     * @access    public
148
     * @return    string
148
     * @return    string
149
     */
149
     */
150
    function getName()
150
    function getName()
151
    {
151
    {
152
        // interface method
152
        // interface method
153
    } //end func getName
153
    } //end func getName
154
    
154
    
155
    // }}}
155
    // }}}
156
    // {{{ setValue()
156
    // {{{ setValue()
157
 
157
 
158
    /**
158
    /**
159
     * Sets the value of the form element
159
     * Sets the value of the form element
160
     *
160
     *
161
     * @param     string    $value      Default value of the form element
161
     * @param     string    $value      Default value of the form element
162
     * @since     1.0
162
     * @since     1.0
163
     * @access    public
163
     * @access    public
164
     * @return    void
164
     * @return    void
165
     */
165
     */
166
    function setValue($value)
166
    function setValue($value)
167
    {
167
    {
168
        // interface
168
        // interface
169
    } // end func setValue
169
    } // end func setValue
170
 
170
 
171
    // }}}
171
    // }}}
172
    // {{{ getValue()
172
    // {{{ getValue()
173
 
173
 
174
    /**
174
    /**
175
     * Returns the value of the form element
175
     * Returns the value of the form element
176
     *
176
     *
177
     * @since     1.0
177
     * @since     1.0
178
     * @access    public
178
     * @access    public
179
     * @return    mixed
179
     * @return    mixed
180
     */
180
     */
181
    function getValue()
181
    function getValue()
182
    {
182
    {
183
        // interface
183
        // interface
184
        return null;
184
        return null;
185
    } // end func getValue
185
    } // end func getValue
186
    
186
    
187
    // }}}
187
    // }}}
188
    // {{{ freeze()
188
    // {{{ freeze()
189
 
189
 
190
    /**
190
    /**
191
     * Freeze the element so that only its value is returned
191
     * Freeze the element so that only its value is returned
192
     * 
192
     * 
193
     * @access    public
193
     * @access    public
194
     * @return    void
194
     * @return    void
195
     */
195
     */
196
    function freeze()
196
    function freeze()
197
    {
197
    {
198
        $this->_flagFrozen = true;
198
        $this->_flagFrozen = true;
199
    } //end func freeze
199
    } //end func freeze
200
 
200
 
201
    // }}}
201
    // }}}
202
    // {{{ unfreeze()
202
    // {{{ unfreeze()
203
 
203
 
204
   /**
204
   /**
205
    * Unfreezes the element so that it becomes editable
205
    * Unfreezes the element so that it becomes editable
206
    *
206
    *
207
    * @access public
207
    * @access public
208
    * @return void
208
    * @return void
209
    * @since  3.2.4
209
    * @since  3.2.4
210
    */
210
    */
211
    function unfreeze()
211
    function unfreeze()
212
    {
212
    {
213
        $this->_flagFrozen = false;
213
        $this->_flagFrozen = false;
214
    }
214
    }
215
 
215
 
216
    // }}}
216
    // }}}
217
    // {{{ getFrozenHtml()
217
    // {{{ getFrozenHtml()
218
 
218
 
219
    /**
219
    /**
220
     * Returns the value of field without HTML tags
220
     * Returns the value of field without HTML tags
221
     * 
221
     * 
222
     * @since     1.0
222
     * @since     1.0
223
     * @access    public
223
     * @access    public
224
     * @return    string
224
     * @return    string
225
     */
225
     */
226
    function getFrozenHtml()
226
    function getFrozenHtml()
227
    {
227
    {
228
        $value = $this->getValue();
228
        $value = $this->getValue();
229
        return ('' != $value? htmlspecialchars($value): '&nbsp;') .
229
        return ('' != $value? htmlspecialchars($value): '&nbsp;') .
230
               $this->_getPersistantData();
230
               $this->_getPersistantData();
231
    } //end func getFrozenHtml
231
    } //end func getFrozenHtml
232
    
232
    
233
    // }}}
233
    // }}}
234
    // {{{ _getPersistantData()
234
    // {{{ _getPersistantData()
235
 
235
 
236
   /**
236
   /**
237
    * Used by getFrozenHtml() to pass the element's value if _persistantFreeze is on
237
    * Used by getFrozenHtml() to pass the element's value if _persistantFreeze is on
238
    * 
238
    * 
239
    * @access private
239
    * @access private
240
    * @return string
240
    * @return string
241
    */
241
    */
242
    function _getPersistantData()
242
    function _getPersistantData()
243
    {
243
    {
244
        if (!$this->_persistantFreeze) {
244
        if (!$this->_persistantFreeze) {
245
            return '';
245
            return '';
246
        } else {
246
        } else {
247
            $id = $this->getAttribute('id');
247
            $id = $this->getAttribute('id');
248
            return '<input type="hidden"' .
248
            return '<input' . $this->_getAttrString(array(
249
                   (isset($id)? ' id="' . $id . '"': '') .
249
                       'type'  => 'hidden',
250
                   ' name="' . $this->getName() . '"' .
250
                       'name'  => $this->getName(),
251
                   ' value="' . htmlspecialchars($this->getValue()) . '" />';
251
                       'value' => $this->getValue()
-
 
252
                   ) + (isset($id)? array('id' => $id): array())) . ' />';
252
        }
253
        }
253
    }
254
    }
254
 
255
 
255
    // }}}
256
    // }}}
256
    // {{{ isFrozen()
257
    // {{{ isFrozen()
257
 
258
 
258
    /**
259
    /**
259
     * Returns whether or not the element is frozen
260
     * Returns whether or not the element is frozen
260
     *
261
     *
261
     * @since     1.3
262
     * @since     1.3
262
     * @access    public
263
     * @access    public
263
     * @return    bool
264
     * @return    bool
264
     */
265
     */
265
    function isFrozen()
266
    function isFrozen()
266
    {
267
    {
267
        return $this->_flagFrozen;
268
        return $this->_flagFrozen;
268
    } // end func isFrozen
269
    } // end func isFrozen
269
 
270
 
270
    // }}}
271
    // }}}
271
    // {{{ setPersistantFreeze()
272
    // {{{ setPersistantFreeze()
272
 
273
 
273
    /**
274
    /**
274
     * Sets wether an element value should be kept in an hidden field
275
     * Sets wether an element value should be kept in an hidden field
275
     * when the element is frozen or not
276
     * when the element is frozen or not
276
     * 
277
     * 
277
     * @param     bool    $persistant   True if persistant value
278
     * @param     bool    $persistant   True if persistant value
278
     * @since     2.0
279
     * @since     2.0
279
     * @access    public
280
     * @access    public
280
     * @return    void
281
     * @return    void
281
     */
282
     */
282
    function setPersistantFreeze($persistant=false)
283
    function setPersistantFreeze($persistant=false)
283
    {
284
    {
284
        $this->_persistantFreeze = $persistant;
285
        $this->_persistantFreeze = $persistant;
285
    } //end func setPersistantFreeze
286
    } //end func setPersistantFreeze
286
 
287
 
287
    // }}}
288
    // }}}
288
    // {{{ setLabel()
289
    // {{{ setLabel()
289
 
290
 
290
    /**
291
    /**
291
     * Sets display text for the element
292
     * Sets display text for the element
292
     * 
293
     * 
293
     * @param     string    $label  Display text for the element
294
     * @param     string    $label  Display text for the element
294
     * @since     1.3
295
     * @since     1.3
295
     * @access    public
296
     * @access    public
296
     * @return    void
297
     * @return    void
297
     */
298
     */
298
    function setLabel($label)
299
    function setLabel($label)
299
    {
300
    {
300
        $this->_label = $label;
301
        $this->_label = $label;
301
    } //end func setLabel
302
    } //end func setLabel
302
 
303
 
303
    // }}}
304
    // }}}
304
    // {{{ getLabel()
305
    // {{{ getLabel()
305
 
306
 
306
    /**
307
    /**
307
     * Returns display text for the element
308
     * Returns display text for the element
308
     * 
309
     * 
309
     * @since     1.3
310
     * @since     1.3
310
     * @access    public
311
     * @access    public
311
     * @return    string
312
     * @return    string
312
     */
313
     */
313
    function getLabel()
314
    function getLabel()
314
    {
315
    {
315
        return $this->_label;
316
        return $this->_label;
316
    } //end func getLabel
317
    } //end func getLabel
317
 
318
 
318
    // }}}
319
    // }}}
319
    // {{{ _findValue()
320
    // {{{ _findValue()
320
 
321
 
321
    /**
322
    /**
322
     * Tries to find the element value from the values array
323
     * Tries to find the element value from the values array
323
     * 
324
     * 
324
     * @since     2.7
325
     * @since     2.7
325
     * @access    private
326
     * @access    private
326
     * @return    mixed
327
     * @return    mixed
327
     */
328
     */
328
    function _findValue(&$values)
329
    function _findValue(&$values)
329
    {
330
    {
330
        if (empty($values)) {
331
        if (empty($values)) {
331
            return null;
332
            return null;
332
        }
333
        }
333
        $elementName = $this->getName();
334
        $elementName = $this->getName();
334
        if (isset($values[$elementName])) {
335
        if (isset($values[$elementName])) {
335
            return $values[$elementName];
336
            return $values[$elementName];
336
        } elseif (strpos($elementName, '[')) {
337
        } elseif (strpos($elementName, '[')) {
337
            $myVar = "['" . str_replace(array(']', '['), array('', "']['"), $elementName) . "']";
338
            $myVar = "['" . str_replace(array(']', '['), array('', "']['"), $elementName) . "']";
338
            return eval("return (isset(\$values$myVar)) ? \$values$myVar : null;");
339
            return eval("return (isset(\$values$myVar)) ? \$values$myVar : null;");
339
        } else {
340
        } else {
340
            return null;
341
            return null;
341
        }
342
        }
342
    } //end func _findValue
343
    } //end func _findValue
343
 
344
 
344
    // }}}
345
    // }}}
345
    // {{{ onQuickFormEvent()
346
    // {{{ onQuickFormEvent()
346
 
347
 
347
    /**
348
    /**
348
     * Called by HTML_QuickForm whenever form event is made on this element
349
     * Called by HTML_QuickForm whenever form event is made on this element
349
     *
350
     *
350
     * @param     string    $event  Name of event
351
     * @param     string    $event  Name of event
351
     * @param     mixed     $arg    event arguments
352
     * @param     mixed     $arg    event arguments
352
     * @param     object    $caller calling object
353
     * @param     object    $caller calling object
353
     * @since     1.0
354
     * @since     1.0
354
     * @access    public
355
     * @access    public
355
     * @return    void
356
     * @return    void
356
     */
357
     */
357
    function onQuickFormEvent($event, $arg, &$caller)
358
    function onQuickFormEvent($event, $arg, &$caller)
358
    {
359
    {
359
        switch ($event) {
360
        switch ($event) {
360
            case 'createElement':
361
            case 'createElement':
361
                $className = get_class($this);
362
                $className = get_class($this);
362
                $this->$className($arg[0], $arg[1], $arg[2], $arg[3], $arg[4]);
363
                $this->$className($arg[0], $arg[1], $arg[2], $arg[3], $arg[4]);
363
                break;
364
                break;
364
            case 'addElement':
365
            case 'addElement':
365
                $this->onQuickFormEvent('createElement', $arg, $caller);
366
                $this->onQuickFormEvent('createElement', $arg, $caller);
366
                $this->onQuickFormEvent('updateValue', null, $caller);
367
                $this->onQuickFormEvent('updateValue', null, $caller);
367
                break;
368
                break;
368
            case 'updateValue':
369
            case 'updateValue':
369
                // constant values override both default and submitted ones
370
                // constant values override both default and submitted ones
370
                // default values are overriden by submitted
371
                // default values are overriden by submitted
371
                $value = $this->_findValue($caller->_constantValues);
372
                $value = $this->_findValue($caller->_constantValues);
372
                if (null === $value) {
373
                if (null === $value) {
373
                    $value = $this->_findValue($caller->_submitValues);
374
                    $value = $this->_findValue($caller->_submitValues);
374
                    if (null === $value) {
375
                    if (null === $value) {
375
                        $value = $this->_findValue($caller->_defaultValues);
376
                        $value = $this->_findValue($caller->_defaultValues);
376
                    }
377
                    }
377
                }
378
                }
378
                if (null !== $value) {
379
                if (null !== $value) {
379
                    $this->setValue($value);
380
                    $this->setValue($value);
380
                }
381
                }
381
                break;
382
                break;
382
            case 'setGroupValue':
383
            case 'setGroupValue':
383
                $this->setValue($arg);
384
                $this->setValue($arg);
384
        }
385
        }
385
        return true;
386
        return true;
386
    } // end func onQuickFormEvent
387
    } // end func onQuickFormEvent
387
 
388
 
388
    // }}}
389
    // }}}
389
    // {{{ accept()
390
    // {{{ accept()
390
 
391
 
391
   /**
392
   /**
392
    * Accepts a renderer
393
    * Accepts a renderer
393
    *
394
    *
394
    * @param object     An HTML_QuickForm_Renderer object
395
    * @param object     An HTML_QuickForm_Renderer object
395
    * @param bool       Whether an element is required
396
    * @param bool       Whether an element is required
396
    * @param string     An error message associated with an element
397
    * @param string     An error message associated with an element
397
    * @access public
398
    * @access public
398
    * @return void 
399
    * @return void 
399
    */
400
    */
400
    function accept(&$renderer, $required=false, $error=null)
401
    function accept(&$renderer, $required=false, $error=null)
401
    {
402
    {
402
        $renderer->renderElement($this, $required, $error);
403
        $renderer->renderElement($this, $required, $error);
403
    } // end func accept
404
    } // end func accept
404
 
405
 
405
    // }}}
406
    // }}}
406
    // {{{ _generateId()
407
    // {{{ _generateId()
407
 
408
 
408
   /**
409
   /**
409
    * Automatically generates and assigns an 'id' attribute for the element.
410
    * Automatically generates and assigns an 'id' attribute for the element.
410
    * 
411
    * 
411
    * Currently used to ensure that labels work on radio buttons and
412
    * Currently used to ensure that labels work on radio buttons and
412
    * checkboxes. Per idea of Alexander Radivanovich.
413
    * checkboxes. Per idea of Alexander Radivanovich.
413
    *
414
    *
414
    * @access private
415
    * @access private
415
    * @return void 
416
    * @return void 
416
    */
417
    */
417
    function _generateId()
418
    function _generateId()
418
    {
419
    {
419
        static $idx = 1;
420
        static $idx = 1;
420
 
421
 
421
        if (!$this->getAttribute('id')) {
422
        if (!$this->getAttribute('id')) {
422
            $this->updateAttributes(array('id' => 'qf_' . substr(md5(microtime() . $idx++), 0, 6)));
423
            $this->updateAttributes(array('id' => 'qf_' . substr(md5(microtime() . $idx++), 0, 6)));
423
        }
424
        }
424
    } // end func _generateId
425
    } // end func _generateId
425
 
426
 
426
    // }}}
427
    // }}}
427
    // {{{ exportValue()
428
    // {{{ exportValue()
428
 
429
 
429
   /**
430
   /**
430
    * Returns a 'safe' element's value
431
    * Returns a 'safe' element's value
431
    *
432
    *
432
    * @param  array   array of submitted values to search
433
    * @param  array   array of submitted values to search
433
    * @param  bool    whether to return the value as associative array
434
    * @param  bool    whether to return the value as associative array
434
    * @access public
435
    * @access public
435
    * @return mixed
436
    * @return mixed
436
    */
437
    */
437
    function exportValue(&$submitValues, $assoc = false)
438
    function exportValue(&$submitValues, $assoc = false)
438
    {
439
    {
439
        $value = $this->_findValue($submitValues);
440
        $value = $this->_findValue($submitValues);
440
        if (null === $value) {
441
        if (null === $value) {
441
            $value = $this->getValue();
442
            $value = $this->getValue();
442
        }
443
        }
443
        return $this->_prepareValue($value, $assoc);
444
        return $this->_prepareValue($value, $assoc);
444
    }
445
    }
445
    
446
    
446
    // }}}
447
    // }}}
447
    // {{{ _prepareValue()
448
    // {{{ _prepareValue()
448
 
449
 
449
   /**
450
   /**
450
    * Used by exportValue() to prepare the value for returning
451
    * Used by exportValue() to prepare the value for returning
451
    *
452
    *
452
    * @param  mixed   the value found in exportValue()
453
    * @param  mixed   the value found in exportValue()
453
    * @param  bool    whether to return the value as associative array
454
    * @param  bool    whether to return the value as associative array
454
    * @access private
455
    * @access private
455
    * @return mixed
456
    * @return mixed
456
    */
457
    */
457
    function _prepareValue($value, $assoc)
458
    function _prepareValue($value, $assoc)
458
    {
459
    {
459
        if (null === $value) {
460
        if (null === $value) {
460
            return null;
461
            return null;
461
        } elseif (!$assoc) {
462
        } elseif (!$assoc) {
462
            return $value;
463
            return $value;
463
        } else {
464
        } else {
464
            $name = $this->getName();
465
            $name = $this->getName();
465
            if (!strpos($name, '[')) {
466
            if (!strpos($name, '[')) {
466
                return array($name => $value);
467
                return array($name => $value);
467
            } else {
468
            } else {
468
                $valueAry = array();
469
                $valueAry = array();
469
                $myIndex  = "['" . str_replace(array(']', '['), array('', "']['"), $name) . "']";
470
                $myIndex  = "['" . str_replace(array(']', '['), array('', "']['"), $name) . "']";
470
                eval("\$valueAry$myIndex = \$value;");
471
                eval("\$valueAry$myIndex = \$value;");
471
                return $valueAry;
472
                return $valueAry;
472
            }
473
            }
473
        }
474
        }
474
    }
475
    }
475
    
476
    
476
    // }}}
477
    // }}}
477
} // end class HTML_QuickForm_element
478
} // end class HTML_QuickForm_element
478
?>
479
?>