[Pieforms-commit] SF.net SVN: pieforms: [90] pieforms-php5/trunk/src/pieform.php
Status: Alpha
Brought to you by:
oracleshinoda
|
From: <ora...@us...> - 2006-12-10 10:59:29
|
Revision: 90
http://svn.sourceforge.net/pieforms/?rev=90&view=rev
Author: oracleshinoda
Date: 2006-12-10 02:59:26 -0800 (Sun, 10 Dec 2006)
Log Message:
-----------
Allowed each element to specify a function that returns an array of HTML items that should be used to set the object up. Useful for calendar/wysiwyg. Also allowed the user to define a function to configure the default form of any element type.
Modified Paths:
--------------
pieforms-php5/trunk/src/pieform.php
Modified: pieforms-php5/trunk/src/pieform.php
===================================================================
--- pieforms-php5/trunk/src/pieform.php 2006-12-10 10:57:41 UTC (rev 89)
+++ pieforms-php5/trunk/src/pieform.php 2006-12-10 10:59:26 UTC (rev 90)
@@ -24,6 +24,8 @@
*
*/
+$GLOBALS['_PIEFORM_REGISTRY'] = array();
+
/**
* Builds, validates and processes a form.
*
@@ -310,6 +312,8 @@
* @param array $data The form description hash
*/
public function __construct($data) {
+ $GLOBALS['_PIEFORM_REGISTRY'][] = $this;
+
if (!isset($data['name']) || !preg_match('/^[a-z_][a-z0-9_]*$/', $data['name'])) {
throw new PieformException('Forms must have a name, and that name must be valid (validity test: could you give a PHP function the name?)');
}
@@ -489,6 +493,16 @@
// Let each element set and override attributes if necessary
if ($subelement['type'] != 'markup') {
+ // This function can be defined by the application using Pieforms,
+ // and applies to all elements of this type
+ $function = 'pieform_configure_' . $subelement['type'];
+ if (function_exists($function)) {
+ $subelement = $function($subelement);
+ }
+
+ // This function is defined by the plugin itself, to set fields on
+ // the element that need to be set but should not be set by the
+ // application
$function = 'pieform_render_' . $subelement['type'] . '_set_attributes';
$this->include_plugin('element', $subelement['type']);
if (function_exists($function)) {
@@ -512,10 +526,12 @@
// Let each element set and override attributes if necessary
if ($element['type'] != 'markup') {
+ $function = 'pieform_configure_' . $element['type'];
+ if (function_exists($function)) {
+ $element = $function($element);
+ }
+
$function = 'pieform_render_' . $element['type'] . '_set_attributes';
- // @todo here, all elements are loaded that will be used, so no
- // need to include files for them later (like in pieform_render_element)
- // Also, don't use require_once so nicer errors can be thrown
$this->include_plugin('element', $element['type']);
if (function_exists($function)) {
$element = $function($element);
@@ -1332,4 +1348,19 @@
return $rendererfunction($form, $builtelement, $element);
}
+function pieform_get_headdata() {
+ $htmlelements = array();
+ foreach ($GLOBALS['_PIEFORM_REGISTRY'] as $form) {
+ foreach ($form->get_elements() as $element) {
+ $function = 'pieform_get_headdata_' . $element['type'];
+ if (function_exists($function)) {
+ $elems = $function($element);
+ $htmlelements = array_merge($htmlelements, $elems);
+ }
+ }
+ }
+
+ return array_unique($htmlelements);
+}
+
?>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|