pieforms-commit Mailing List for Pieforms (Page 9)
Status: Alpha
Brought to you by:
oracleshinoda
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(73) |
Dec
(83) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(16) |
Feb
(19) |
Mar
(12) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
(14) |
Sep
(2) |
Oct
(1) |
Nov
(2) |
Dec
(45) |
2008 |
Jan
(20) |
Feb
(3) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
(3) |
Aug
|
Sep
|
Oct
(1) |
Nov
(1) |
Dec
(1) |
2009 |
Jan
(2) |
Feb
(2) |
Mar
|
Apr
(2) |
May
(1) |
Jun
(5) |
Jul
(1) |
Aug
(2) |
Sep
(1) |
Oct
|
Nov
(7) |
Dec
|
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <ora...@us...> - 2006-12-23 04:08:20
|
Revision: 123 http://svn.sourceforge.net/pieforms/?rev=123&view=rev Author: oracleshinoda Date: 2006-12-22 20:08:19 -0800 (Fri, 22 Dec 2006) Log Message: ----------- Updated to use the new APIs. Now passes its value through correctly if it is used for submission. Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/image.php Modified: pieforms-php5/trunk/src/pieform/elements/image.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/image.php 2006-12-23 04:07:30 UTC (rev 122) +++ pieforms-php5/trunk/src/pieform/elements/image.php 2006-12-23 04:08:19 UTC (rev 123) @@ -27,19 +27,38 @@ /** * Renders an <input type="image"> button * + * @param Pieform $form The form to render the element for * @param array $element The element to render - * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function pieform_render_image($element, Pieform $form) { +function pieform_element_image(Pieform $form, $element) { + if (!isset($element['src'])) { + throw new PieformException('"image" elements must have a "src" for the image'); + } + if (!isset($element['value'])) { + $element['value'] = true; + } return '<input type="image" src="' . Pieform::hsc($element['src']) . '"' . $form->element_attributes($element) . ' value="' . Pieform::hsc($form->get_value($element)) . '">'; } -function pieform_render_image_set_attributes($element) { +function pieform_element_image_set_attributes($element) { $element['ajaxmessages'] = true; return $element; } +function pieform_element_image_get_value(Pieform $form, $element) { + if (isset($element['value'])) { + return $element['value']; + } + + $global = $form->get_property('method') == 'get' ? $_GET : $_POST; + if (isset($global[$element['name'] . '_x'])) { + return true; + } + + return null; +} + ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-23 04:07:30
|
Revision: 122 http://svn.sourceforge.net/pieforms/?rev=122&view=rev Author: oracleshinoda Date: 2006-12-22 20:07:30 -0800 (Fri, 22 Dec 2006) Log Message: ----------- Updated to use the new APIs. Also behaves better when the required rule is set Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/expiry.php Modified: pieforms-php5/trunk/src/pieform/elements/expiry.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/expiry.php 2006-12-23 04:06:32 UTC (rev 121) +++ pieforms-php5/trunk/src/pieform/elements/expiry.php 2006-12-23 04:07:30 UTC (rev 122) @@ -28,33 +28,33 @@ * Provides a duration chooser, with a text box for a number and a * select box to choose the units, in days, weeks, months, years, or 'no end date'. * - * @param array $element The element to render - * @param Pieform $form The form to render the element for - * @return string The HTML for the element + * @param Pieform $form The form to render the element for + * @param array $element The element to render + * @return string The HTML for the element */ -function pieform_render_expiry($element, Pieform $form) { +function pieform_element_expiry(Pieform $form, $element) { $result = ''; $name = $element['name']; if (!isset($element['defaultvalue'])) { $element['defaultvalue'] = null; } - $global = ($form->get_method() == 'get') ? $_GET : $_POST; + $global = ($form->get_property('method') == 'get') ? $_GET : $_POST; // Get the value of the element for rendering. if (isset($element['value'])) { $seconds = $element['value']; - $values = pieform_render_expiry_get_expiry_from_seconds($element['value']); + $values = pieform_element_expiry_get_expiry_from_seconds($element['value']); } else if (isset($global[$element['name'] . '_number']) && isset($global[$element['name'] . '_units'])) { $values = array('number' => $global[$element['name'] . '_number'], 'units' => $global[$element['name'] . '_units']); - $seconds = $values['number'] * pieform_render_expiry_seconds_in($values['units']); + $seconds = $values['number'] * pieform_element_expiry_seconds_in($values['units']); } else if (isset($element['defaultvalue'])) { $seconds = $element['defaultvalue']; - $values = pieform_render_expiry_get_expiry_from_seconds($seconds); + $values = pieform_element_expiry_get_expiry_from_seconds($seconds); } else { $values = array('number' => '', 'units' => 'noenddate'); @@ -64,14 +64,20 @@ // @todo probably create with an actual input element, as tabindex doesn't work here for one thing // Same with the select. And do the events using mochikit signal instead of dom events $numberinput = '<input'; - $numberinput .= $values['units'] == 'noenddate' ? ' disabled="disabled"' : ''; + $numberinput .= ($values['units'] == 'noenddate' && empty($element['rules']['required'])) ? ' disabled="disabled"' : ''; $numberinput .= ' type="text" size="4" name="' . $name . '_number"'; $numberinput .= ' id="' . $name . '_number" value="' . $values['number'] . '" tabindex="' . $element['tabindex'] . "\">\n"; $uselect = '<select onchange="' . $name . '_change()" '; $uselect .= 'name="' . $name . '_units" id="' . $name . '_units"' . ' tabindex="' . $element['tabindex'] . "\">\n"; - foreach (pieform_render_expire_get_expiry_units() as $u) { - $uselect .= "\t<option value=\"$u\"" . (($values['units'] == $u) ? ' selected="selected"' : '') . '>' . $form->i18n($u) . "</option>\n"; + foreach (pieform_element_expire_get_expiry_units() as $u) { + // Don't allow 'no end date' if the element is required + if ($u == 'noenddate' && !empty($element['rules']['required'])) { + continue; + } + + $uselect .= "\t<option value=\"$u\"" . (($values['units'] == $u) ? ' selected="selected"' : '') . '>' + . $form->i18n('element', 'expiry', $u, $element) . "</option>\n"; } $uselect .= "</select>\n"; @@ -92,71 +98,78 @@ return $numberinput . $uselect . $script; } -function pieform_render_expire_get_expiry_units() { +/** + * Gets the value of the expiry element and converts it to a time in seconds. + * + * @param Pieform $form The form the element is attached to + * @param array $element The element to get the value for + * @return int The number of seconds until expiry + */ +function pieform_element_expiry_get_value(Pieform $form, $element) { + $name = $element['name']; + $global = ($form->get_property('method') == 'get') ? $_GET : $_POST; + $unit = $global[$name . '_units']; + if ($unit == 'noenddate') { + return null; + } + $allunits = pieform_element_expire_get_expiry_units(); + $number = $global[$name . '_number']; + if (!in_array($unit,$allunits) || $number < 0) { + return null; + } + return $number * pieform_element_expiry_seconds_in($unit); +} + +function pieform_element_expiry_i18n() { + return array( + 'en.utf8' => array( + 'days' => 'Days', + 'weeks' => 'Weeks', + 'months' => 'Months', + 'years' => 'Years', + 'noenddate' => 'No end date' + ) + ); +} + +function pieform_element_expire_get_expiry_units() { return array('days', 'weeks', 'months', 'years', 'noenddate'); } -function pieform_render_expiry_seconds_in($unit) { +function pieform_element_expiry_seconds_in($unit) { $dayseconds = 60 * 60 * 24; switch ($unit) { - case 'days' : return $dayseconds; - case 'weeks' : return $dayseconds * 7; - case 'months' : return $dayseconds * 30; - case 'years' : return $dayseconds * 365; - default : return null; + case 'days' : return $dayseconds; + case 'weeks' : return $dayseconds * 7; + case 'months' : return $dayseconds * 30; + case 'years' : return $dayseconds * 365; + default : return null; } } -function pieform_render_expiry_get_expiry_from_seconds($seconds) { +function pieform_element_expiry_get_expiry_from_seconds($seconds) { if ($seconds == null) { return array('number' => '', 'units' => 'noenddate'); } // This needs work to produce sensible values; at the moment it will convert // 60 days into 2 months; 70 days into 7 weeks, etc. - $yearseconds = pieform_render_expiry_seconds_in('years'); + $yearseconds = pieform_element_expiry_seconds_in('years'); if ($seconds % $yearseconds == 0 && $seconds > 0) { return array('number' => (int) ($seconds / $yearseconds), 'units' => 'years'); } - $monthseconds = pieform_render_expiry_seconds_in('months'); + $monthseconds = pieform_element_expiry_seconds_in('months'); if ($seconds % $monthseconds == 0 && $seconds > 0) { return array('number' => (int) ($seconds / $monthseconds), 'units' => 'months'); } - $weekseconds = pieform_render_expiry_seconds_in('weeks'); + $weekseconds = pieform_element_expiry_seconds_in('weeks'); if ($seconds % $weekseconds == 0 && $seconds > 0) { return array('number' => (int) ($seconds / $weekseconds), 'units' => 'weeks'); } - $dayseconds = pieform_render_expiry_seconds_in('days'); + $dayseconds = pieform_element_expiry_seconds_in('days'); if ($seconds % $dayseconds == 0) { return array('number' => (int) ($seconds / $dayseconds), 'units' => 'days'); } return null; } -// /** gets the value explicitly from the request */ -function pieform_get_value_expiry($element, Pieform $form) { - $name = $element['name']; - $global = ($form->get_method() == 'get') ? $_GET : $_POST; - //return $global[$name]; - $unit = $global[$name . '_units']; - if ($unit == 'noenddate') { - return null; - } - $allunits = pieform_render_expire_get_expiry_units(); - $number = $global[$name . '_number']; - if (!in_array($unit,$allunits) || $number < 0) { - return null; - } - return $number * pieform_render_expiry_seconds_in($unit); -} - -function pieform_get_value_js_expiry($element, Pieform $form) { - $formname = $form->get_name(); - $name = $element['name']; - return <<<EOF - data['{$name}_number'] = $('{$name}_number').value; - data['{$name}_units'] = $('{$name}_units').value; - -EOF; -} - ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-23 04:06:35
|
Revision: 121 http://svn.sourceforge.net/pieforms/?rev=121&view=rev Author: oracleshinoda Date: 2006-12-22 20:06:32 -0800 (Fri, 22 Dec 2006) Log Message: ----------- Updated to use the new APIs. Use Pieform::info so that people can acutally use it Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/select.php Modified: pieforms-php5/trunk/src/pieform/elements/select.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/select.php 2006-12-23 04:05:37 UTC (rev 120) +++ pieforms-php5/trunk/src/pieform/elements/select.php 2006-12-23 04:06:32 UTC (rev 121) @@ -27,11 +27,11 @@ /** * Renders a dropdown list, including support for multiple choices. * - * @param array $element The element to render * @param Pieform $form The form to render the element for + * @param array $element The element to render * @return string The HTML for the element */ -function pieform_render_select($element, Pieform $form) { +function pieform_element_select(Pieform $form, $element) { if (!empty($element['multiple'])) { $element['name'] .= '[]'; } @@ -49,7 +49,7 @@ . ">\n"; if (!isset($element['options']) || !is_array($element['options']) || count($element['options']) < 1) { $result .= "\t<option></option>\n"; - log_warn('Select elements should have at least one option'); + Pieform::info('Select elements should have at least one option'); } if (empty($element['multiple'])) { @@ -59,6 +59,7 @@ if (isset($element['value'])) { $values = (array) $element['value']; } + // @todo use $global instead of $_POST else if (isset($_POST[$element['name']])) { $values = (array) $_POST[$element['name']]; } @@ -69,9 +70,11 @@ $values = array(); } } + $optionselected = false; foreach ($element['options'] as $key => $value) { if (in_array($key, $values)) { $selected = ' selected="selected"'; + $optionselected = true; } else { $selected = ''; @@ -79,24 +82,15 @@ $result .= "\t<option value=\"" . Pieform::hsc($key) . "\"$selected>" . Pieform::hsc($value) . "</option>\n"; } + if (!$optionselected && $values) { + Pieform::info('Invalid value for select "' . $element['name'] .'"'); + } + $result .= '</select>'; return $result; } -function pieform_get_value_js_select($element, Pieform $form) { - $formname = $form->get_name(); - $name = $element['name']; - if ($element['collapseifoneoption']) { - return " data['$name'] = document.forms['$formname'].elements['$name'].value;\n"; - } - return <<<EOF - var select = filter(function(option) { return option.selected; }, document.forms['$formname'].elements['$name'].options); - data['$name'] = map(function(o) { return o.value; }, select); - -EOF; -} - -function pieform_render_select_set_attributes($element) { +function pieform_element_select_set_attributes($element) { $element['collapseifoneoption'] = true; $element['rules']['validateoptions'] = true; return $element; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-23 04:05:36
|
Revision: 120 http://svn.sourceforge.net/pieforms/?rev=120&view=rev Author: oracleshinoda Date: 2006-12-22 20:05:37 -0800 (Fri, 22 Dec 2006) Log Message: ----------- Updated to use the new API. Removed done TODOs Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/file.php Modified: pieforms-php5/trunk/src/pieform/elements/file.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/file.php 2006-12-23 04:04:50 UTC (rev 119) +++ pieforms-php5/trunk/src/pieform/elements/file.php 2006-12-23 04:05:37 UTC (rev 120) @@ -27,16 +27,16 @@ /** * Renders a basic HTML <input type="file"> element. * - * @param array $element The element to render - * @param Pieform $form The form to render the element for + * @param Pieform $form The form to render the element for + * @param array $element The element to render * @return string The HTML for the element */ -function pieform_render_file($element, Pieform $form) { +function pieform_element_file(Pieform $form, $element) { return '<input type="file"' . $form->element_attributes($element) . '>'; } -function pieform_get_value_file($element, Pieform $form) { +function pieform_element_file_get_value(Pieform $form, $element) { if (isset($_FILES[$element['name']])) { if (!$_FILES[$element['name']]['error']) { return $_FILES[$element['name']]; @@ -52,8 +52,4 @@ return true; } -// @todo: provide a mechanism for elements to claim they deal with files. -// If this is triggered, the forms is forced to POST and the enctype stuff -// is added. -// @todo is enctype required for ajax submission of files? ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-23 04:04:49
|
Revision: 119 http://svn.sourceforge.net/pieforms/?rev=119&view=rev Author: oracleshinoda Date: 2006-12-22 20:04:50 -0800 (Fri, 22 Dec 2006) Log Message: ----------- Updated to use the new APIs. Use Pieform::info so that people can acutally use it Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/textarea.php Modified: pieforms-php5/trunk/src/pieform/elements/textarea.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/textarea.php 2006-12-23 04:04:11 UTC (rev 118) +++ pieforms-php5/trunk/src/pieform/elements/textarea.php 2006-12-23 04:04:50 UTC (rev 119) @@ -31,7 +31,7 @@ * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function pieform_render_textarea($element, Pieform $form) { +function pieform_element_textarea(Pieform $form, $element) { $rows = $cols = $style = ''; if (isset($element['height'])) { $style .= 'height:' . $element['height'] . ';'; @@ -41,7 +41,7 @@ $rows = $element['rows']; } else { - log_warn('No value for rows or height specified for textarea ' . $element['name']); + Pieform::info('No value for rows or height specified for textarea "' . $element['name'] . '"'); } if (isset($element['width'])) { @@ -52,7 +52,7 @@ $cols = $element['cols']; } else { - log_warn('No value for cols or width specified for textarea ' . $element['name']); + Pieform::info('No value for cols or width specified for textarea "' . $element['name'] . '"'); } $element['style'] = (isset($element['style'])) ? $style . $element['style'] : $style; return '<textarea' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-23 04:04:11
|
Revision: 118 http://svn.sourceforge.net/pieforms/?rev=118&view=rev Author: oracleshinoda Date: 2006-12-22 20:04:11 -0800 (Fri, 22 Dec 2006) Log Message: ----------- Updated to use the new APIs. The 'optional' flag is now gone, replaced with responding to the 'required' rule, which makes much more sense Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/date.php Modified: pieforms-php5/trunk/src/pieform/elements/date.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/date.php 2006-12-23 04:03:12 UTC (rev 117) +++ pieforms-php5/trunk/src/pieform/elements/date.php 2006-12-23 04:04:11 UTC (rev 118) @@ -27,38 +27,45 @@ /** * Provides a date picker, in the form of three dropdowns. * + * @param Pieform $form The form to render the element for * @param array $element The element to render - * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function pieform_render_date($element, Pieform $form) { +function pieform_element_date(Pieform $form, $element) { $result = ''; - $name = $element['name']; + $name = $element['name']; $element['minyear'] = (isset($element['minyear'])) ? intval($element['minyear']) : 1950; $element['maxyear'] = (isset($element['maxyear'])) ? intval($element['maxyear']) : 2050; - if (!array_key_exists('defaultvalue', $element)) { + if (!isset($element['defaultvalue'])) { $element['defaultvalue'] = time(); } + $required = (!empty($element['rules']['required'])); // Year - $value = pieform_render_select_get_value('year', $element['minyear'], $element['maxyear'], $element, $form); - $year = '<select name="' . $name . '_year" id="' . $name . '_year"' . (isset($element['optional']) && !isset($element['defaultvalue']) ? ' disabled="disabled"' : '') . ">\n"; + $value = pieform_element_date_get_timeperiod_value('year', $element['minyear'], $element['maxyear'], $element, $form); + $year = '<select name="' . $name . '_year" id="' . $name . '_year"' + . (!$required && !isset($element['defaultvalue']) ? ' disabled="disabled"' : '') + . ' tabindex="' . $element['tabindex'] . "\">\n"; for ($i = $element['minyear']; $i <= $element['maxyear']; $i++) { $year .= "\t<option value=\"$i\"" . (($value == $i) ? ' selected="selected"' : '') . ">$i</option>\n"; } $year .= "</select>\n"; // Month - $value = pieform_render_select_get_value('month', 1, 12, $element, $form); - $month = '<select name="' . $name . '_month" id="' . $name . '_month"' . (isset($element['optional']) && !isset($element['defaultvalue']) ? ' disabled="disabled"' : '') . ">\n"; + $value = pieform_element_date_get_timeperiod_value('month', 1, 12, $element, $form); + $month = '<select name="' . $name . '_month" id="' . $name . '_month"' + . (!$required && !isset($element['defaultvalue']) ? ' disabled="disabled"' : '') + . ' tabindex="' . $element['tabindex'] . "\">\n"; for ($i = 1; $i <= 12; $i++) { $month .= "\t<option value=\"$i\"" . (($value == $i) ? ' selected="selected"' : '') . '>' . date('M', strtotime("2000-$i-01")) . "</option>\n"; } $month .= "</select>\n"; // Day - $value = pieform_render_select_get_value('day', 1, 31, $element, $form); - $day = '<select name="' . $name . '_day" id="' . $name . '_day"' . (isset($element['optional']) && !isset($element['defaultvalue']) ? ' disabled="disabled"' : '') . ">\n"; + $value = pieform_element_date_get_timeperiod_value('day', 1, 31, $element, $form); + $day = '<select name="' . $name . '_day" id="' . $name . '_day"' + . (!$required && !isset($element['defaultvalue']) ? ' disabled="disabled"' : '') + . ' tabindex="' . $element['tabindex'] . "\">\n"; for ($i = 1; $i <= 31; $i++) { $day .= "\t<option value=\"$i\"" . (($value == $i) ? ' selected="selected"' : '') . ">$i</option>\n"; } @@ -67,7 +74,7 @@ $result = $year . $month . $day; // Optional control - if (isset($element['optional'])) { + if (!$required) { $optional = <<<EOF <script type="text/javascript"> function {$name}_toggle(x) { @@ -87,8 +94,11 @@ // @todo this needs cleaning up, namely: // - get_string is a mahara-ism // - 'optional' => true should be 'required' => false shouldn't it? - $optional .= ' ' . get_string('or') . ' <input type="checkbox" ' . ( isset($element['defaultvalue']) ? '' : 'checked ') . 'name="' . $name . '_optional" id="' . $name . '_optional" onchange="' . $name . '_toggle(this)">'; - $optional .= ' <label for="' . $name . '_optional">' . get_string('notspecified'); + $optional .= ' ' . $form->i18n('element', 'date', 'or', $element) . ' <input type="checkbox" ' + . (isset($element['defaultvalue']) ? '' : 'checked="checked" ') + . 'name="' . $name . '_optional" id="' . $name . '_optional" onchange="' . $name . '_toggle(this)" ' + . 'tabindex="' . $element['tabindex'] . '">'; + $optional .= ' <label for="' . $name . '_optional">' . $form->i18n('element', 'date', 'notspecified', $element); $result .= $optional; } @@ -96,10 +106,16 @@ return $result; } -/** gets the value explicitly from the request */ -function pieform_get_value_date($element, Pieform $form) { +/** + * Gets the value of the date element from the request and converts it into a + * unix timestamp. + * + * @param Pieform $form The form the element is attached to + * @param array $element The element to get the value for + */ +function pieform_element_date_get_value(Pieform $form, $element) { $name = $element['name']; - $global = ($form->get_method() == 'get') ? $_GET : $_POST; + $global = ($form->get_property('method') == 'get') ? $_GET : $_POST; if ( isset($global[$name . '_day']) && isset($global[$name . '_month']) && isset($global[$name . '_year']) ) { $time = mktime(0, 0, 0, $global[$name . '_month'], $global[$name . '_day'], $global[$name . '_year']); if (false === $time) { @@ -111,19 +127,17 @@ return null; } -function pieform_get_value_js_date($element, Pieform $form) { - $formname = $form->get_name(); - $name = $element['name']; - return <<<EOF - data['{$name}_year'] = document.forms['$formname'].elements['{$name}_year'].value; - data['{$name}_month'] = document.forms['$formname'].elements['{$name}_month'].value; - data['{$name}_day'] = document.forms['$formname'].elements['{$name}_day'].value; - -EOF; +function pieform_element_date_i18n() { + return array( + 'en.utf8' => array( + 'or' => 'or', + 'notspecified' => 'Not specified' + ) + ); } /** helper: used when rendering the element, to get the value for it */ -function pieform_render_select_get_value($timeperiod, $min, $max, $element, Pieform $form) { +function pieform_element_date_get_timeperiod_value($timeperiod, $min, $max, $element, Pieform $form) { static $lookup = array( 'year' => 0, 'month' => 1, @@ -139,7 +153,7 @@ return $value; } - $global = ($form->get_method() == 'get') ? $_GET : $_POST; + $global = ($form->get_property('method') == 'get') ? $_GET : $_POST; if (isset($global[$element['name'] . '_' . $timeperiod])) { $value = $global[$element['name'] . '_' . $timeperiod]; if ($value < $min || $value > $max) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-23 04:03:11
|
Revision: 117 http://svn.sourceforge.net/pieforms/?rev=117&view=rev Author: oracleshinoda Date: 2006-12-22 20:03:12 -0800 (Fri, 22 Dec 2006) Log Message: ----------- Updated to use the new API Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/button.php Modified: pieforms-php5/trunk/src/pieform/elements/button.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/button.php 2006-12-23 04:01:31 UTC (rev 116) +++ pieforms-php5/trunk/src/pieform/elements/button.php 2006-12-23 04:03:12 UTC (rev 117) @@ -29,11 +29,12 @@ * * The element must have the 'value' field set. * - * @param array $element The element to render - * @param Pieform $form The form to render the element for - * @return string The HTML for the element + * @param Pieform $form The form to render the element for + * @param array $element The element to render + * @return string The HTML for the element + * @todo rename to inputbutton */ -function pieform_render_button($element, Pieform $form) { +function pieform_element_button(Pieform $form, $element) { if (!isset($element['value'])) { throw new PieformException('Button elements must have a value'); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-23 04:01:32
|
Revision: 116 http://svn.sourceforge.net/pieforms/?rev=116&view=rev Author: oracleshinoda Date: 2006-12-22 20:01:31 -0800 (Fri, 22 Dec 2006) Log Message: ----------- Updated to use the new API. Furthermore, now correctly returns its value when it has been used for submission Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/submitcancel.php Modified: pieforms-php5/trunk/src/pieform/elements/submitcancel.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/submitcancel.php 2006-12-23 03:57:27 UTC (rev 115) +++ pieforms-php5/trunk/src/pieform/elements/submitcancel.php 2006-12-23 04:01:31 UTC (rev 116) @@ -27,23 +27,36 @@ /** * Renders a submit and cancel button * + * @param Pieform $form The form to render the element for * @param array $element The element to render - * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function pieform_render_submitcancel($element, Pieform $form) { +function pieform_element_submitcancel(Pieform $form, $element) { + if (!isset($element['value']) || !is_array($element['value']) || count($element['value']) != 2) { + throw new PieformException('The submitcancel element "' . $element['name'] + . '" must have a two element array for its value'); + } $form->include_plugin('element', 'submit'); $form->include_plugin('element', 'cancel'); $submitelement = $element; $submitelement['value'] = $element['value'][0]; $cancelelement = $element; $cancelelement['value'] = $element['value'][1]; - return pieform_render_submit($submitelement, $form) . ' ' . pieform_render_cancel($cancelelement, $form); + return pieform_element_submit($form, $submitelement) . ' ' . pieform_element_cancel($form, $cancelelement); } -function pieform_render_submitcancel_set_attributes($element) { +function pieform_element_submitcancel_set_attributes($element) { $element['ajaxmessages'] = true; return $element; } +function pieform_element_submitcancel_get_value(Pieform $form, $element) { + if (is_array($element['value'])) { + return $element['value'][0]; + } + else { + return $element['value']; + } +} + ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-23 03:57:37
|
Revision: 115 http://svn.sourceforge.net/pieforms/?rev=115&view=rev Author: oracleshinoda Date: 2006-12-22 19:57:27 -0800 (Fri, 22 Dec 2006) Log Message: ----------- Updated to use the new API. Corrected tabindex too. Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/calendar.php Modified: pieforms-php5/trunk/src/pieform/elements/calendar.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/calendar.php 2006-12-23 03:56:23 UTC (rev 114) +++ pieforms-php5/trunk/src/pieform/elements/calendar.php 2006-12-23 03:57:27 UTC (rev 115) @@ -30,23 +30,32 @@ * General documentation about the calendar is available at * http://www.dynarch.com/demos/jscalendar/doc/html/reference.html * + * @param Pieform $form The form to render the element for * @param array $element The element to render - * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function pieform_render_calendar($element, Pieform $form) { +function pieform_element_calendar(Pieform $form, $element) { $id = $form->get_name() . '_' . $element['name']; + $value = $form->get_value($element); + if ($value) { + $value = Pieform::hsc(strftime($element['caloptions']['ifFormat'], $value)); + } + + // Build the HTML $result = '<input type="text"' . $form->element_attributes($element) - . ' value="' . ( $form->get_value($element) ? Pieform::hsc(strftime($element['caloptions']['ifFormat'],$form->get_value($element))) : '' ) . '">'; + . ' value="' . $value . '">'; if (isset($element['imagefile'])) { - $result .= '<a href="" id="'. $id . '_btn" onclick="return false;" class="pieform-calendar-toggle">' + $result .= '<a href="" id="'. $id . '_btn" onclick="return false;" class="pieform-calendar-toggle"' + . ' tabindex="' . $element['tabindex'] . '">' . '<img src="' . $element['imagefile'] . '" alt=""></a>'; } else { - $result .= '<input type="button" id="' . $id . '_btn" onclick="return false;" class="pieform-calendar-toggle" value="...">'; + $result .= '<input type="button" id="' . $id . '_btn" onclick="return false;" class="pieform-calendar-toggle"' + . ' value="..." tabindex="' . $element['tabindex'] . '">'; } + // Build the configuring javascript $options = array_merge($element['caloptions'], array('inputField' => $id, 'button' => $id . '_btn')); $encodedoptions = json_encode($options); @@ -55,10 +64,17 @@ $encodedoptions = preg_replace('/("' . $function . '"):"([a-zA-Z0-9$]+)"/', '\1:\2', $encodedoptions); } $result .= '<script type="text/javascript">Calendar.setup(' . $encodedoptions . ');</script>'; + return $result; } -function pieform_render_calendar_set_attributes($element) { +/** + * Sets default attributes of the calendar element. + * + * @param array $element The element to configure + * @return array The configured element + */ +function pieform_element_calendar_set_attributes($element) { $element['jsroot'] = isset($element['jsroot']) ? $element['jsroot'] : ''; $element['language'] = isset($element['language']) ? $element['language'] : 'en'; $element['theme'] = isset($element['theme']) ? $element['theme'] : 'calendar-win2k-2'; @@ -67,8 +83,13 @@ return $element; } -/** Returns code to go in <head> for all instances of calendar */ -function pieform_get_headdata_calendar($element) { +/** + * Returns code to go in <head> for the given calendar instance + * + * @param array $element The element to get <head> code for + * @return array An array of HTML elements to go in the <head> + */ +function pieform_element_calendar_get_headdata($element) { if (isset($element['themefile'])) { $themefile = $element['themefile']; } @@ -90,11 +111,17 @@ return $result; } -function pieform_get_value_calendar($element, Pieform $form) { +/** + * Retrieves the value of the calendar as a unix timestamp + * + * @param Pieform $form The form the element is attached to + * @param array $element The element to get the value for + * @return int The unix timestamp represented by the calendar + */ +function pieform_element_calendar_get_value(Pieform $form, $element) { $name = $element['name']; + $global = ($form->get_property('method') == 'get') ? $_GET : $_POST; - $global = ($form->get_method() == 'get') ? $_GET : $_POST; - if (isset($element['value'])) { return $element['value']; } @@ -107,7 +134,7 @@ $value = strtotime($global[$name]); if ($value === false) { - $form->set_error($name, 'TODO'); + $form->set_error($name, 'TODO (error for invalid calendar value)'); return null; } return $value; @@ -120,6 +147,4 @@ return null; } -// TODO: (possibly, also might need the javascript version for ajax forms) - ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-23 03:56:23
|
Revision: 114 http://svn.sourceforge.net/pieforms/?rev=114&view=rev Author: oracleshinoda Date: 2006-12-22 19:56:23 -0800 (Fri, 22 Dec 2006) Log Message: ----------- Updated to use the new API. Also correctly prevent focus from applying to them Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/html.php Modified: pieforms-php5/trunk/src/pieform/elements/html.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/html.php 2006-12-23 03:54:18 UTC (rev 113) +++ pieforms-php5/trunk/src/pieform/elements/html.php 2006-12-23 03:56:23 UTC (rev 114) @@ -32,17 +32,14 @@ * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function pieform_render_html($element, Pieform $form) { +function pieform_element_html(Pieform $form, $element) { return $element['value']; } -function pieform_render_html_set_attributes($element) { +function pieform_element_html_set_attributes($element) { $element['nolabel'] = true; + $element['nofocus'] = true; return $element; } -function pieform_get_value_js_html() { - return ''; -} - ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-23 03:54:19
|
Revision: 113 http://svn.sourceforge.net/pieforms/?rev=113&view=rev Author: oracleshinoda Date: 2006-12-22 19:54:18 -0800 (Fri, 22 Dec 2006) Log Message: ----------- Updated elements to new API Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/submit.php Modified: pieforms-php5/trunk/src/pieform/elements/submit.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/submit.php 2006-12-23 03:50:31 UTC (rev 112) +++ pieforms-php5/trunk/src/pieform/elements/submit.php 2006-12-23 03:54:18 UTC (rev 113) @@ -27,17 +27,17 @@ /** * Renders a submit button * + * @param Pieform $form The form to render the element for * @param array $element The element to render - * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function pieform_render_submit($element, Pieform $form) { +function pieform_element_submit(Pieform $form, $element) { return '<input type="submit"' . $form->element_attributes($element) . ' value="' . Pieform::hsc($form->get_value($element)) . '">'; } -function pieform_render_submit_set_attributes($element) { +function pieform_element_submit_set_attributes($element) { $element['ajaxmessages'] = true; return $element; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-23 03:50:33
|
Revision: 112 http://svn.sourceforge.net/pieforms/?rev=112&view=rev Author: oracleshinoda Date: 2006-12-22 19:50:31 -0800 (Fri, 22 Dec 2006) Log Message: ----------- Updated elements to new API Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/fieldset.php pieforms-php5/trunk/src/pieform/elements/password.php pieforms-php5/trunk/src/pieform/elements/radio.php Modified: pieforms-php5/trunk/src/pieform/elements/fieldset.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/fieldset.php 2006-12-23 03:48:43 UTC (rev 111) +++ pieforms-php5/trunk/src/pieform/elements/fieldset.php 2006-12-23 03:50:31 UTC (rev 112) @@ -28,11 +28,11 @@ * Renders a fieldset. Fieldsets contain other elements, and do not count as a * "true" element, in that they do not have a value and cannot be validated. * - * @param array $element The element to render - * @param Pieform $form The form to render the element for - * @return string The HTML for the element + * @param Pieform $form The form to render the element for + * @param array $element The element to render + * @return string The HTML for the element */ -function pieform_render_fieldset($element, Pieform $form) { +function pieform_element_fieldset(Pieform $form, $element) { $result = "\n<fieldset>\n"; if (isset($element['legend'])) { $result .= '<legend>' . Pieform::hsc($element['legend']) . "</legend>\n"; @@ -42,7 +42,7 @@ if ($subelement['type'] == 'hidden') { throw new PieformError("You cannot put hidden elements in fieldsets"); } - $result .= "\t" . pieform_render_element($subelement, $form); + $result .= "\t" . pieform_render_element($form, $subelement); } $result .= "</fieldset>\n"; Modified: pieforms-php5/trunk/src/pieform/elements/password.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/password.php 2006-12-23 03:48:43 UTC (rev 111) +++ pieforms-php5/trunk/src/pieform/elements/password.php 2006-12-23 03:50:31 UTC (rev 112) @@ -31,14 +31,14 @@ * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function pieform_render_password($element, Pieform $form) { +function pieform_element_password(Pieform $form, $element) { return '<input type="password"' . $form->element_attributes($element) . ' value="' . Pieform::hsc($form->get_value($element)) . '">'; } -function pieform_get_value_password($element, Pieform $form) { - $global = ($form->get_method() == 'get') ? $_GET : $_POST; +function pieform_element_password_get_value(Pieform $form, $element) { + $global = ($form->get_property('method') == 'get') ? $_GET : $_POST; if (isset($global[$element['name']])) { return $global[$element['name']]; } Modified: pieforms-php5/trunk/src/pieform/elements/radio.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/radio.php 2006-12-23 03:48:43 UTC (rev 111) +++ pieforms-php5/trunk/src/pieform/elements/radio.php 2006-12-23 03:50:31 UTC (rev 112) @@ -31,7 +31,7 @@ * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function pieform_render_radio($element, Pieform $form) { +function pieform_element_radio(Pieform $form, $element) { if (!isset($element['options']) || !is_array($element['options']) || count($element['options']) < 1) { throw new PieformException('Radio elements should have at least one option'); } @@ -59,25 +59,7 @@ return $result; } -/** - * radio doesn't need a function to get a value from phpland because it comes - * through correctly from the request... however in javascript land things are - * harder. - * - * @todo maybe later: make the get_value_js functions return a javascript function, - * to keep their stuff in its own scope. Maybe. If js scoping rules mean this will help. - */ -function pieform_get_value_js_radio($element, Pieform $form) { - $formname = $form->get_name(); - $name = $element['name']; - return <<<EOF - var radio = filter(function(radio) { return radio.checked; }, document.forms['$formname'].elements['$name']); - data['$name'] = radio[0].value; - -EOF; -} - -function pieform_render_radio_set_attributes($element) { +function pieform_element_radio_set_attributes($element) { $element['nolabel'] = true; $element['rules']['validateoptions'] = true; return $element; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-23 03:48:42
|
Revision: 111 http://svn.sourceforge.net/pieforms/?rev=111&view=rev Author: oracleshinoda Date: 2006-12-22 19:48:43 -0800 (Fri, 22 Dec 2006) Log Message: ----------- Updated hidden element for new API Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/hidden.php Modified: pieforms-php5/trunk/src/pieform/elements/hidden.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/hidden.php 2006-12-23 03:48:02 UTC (rev 110) +++ pieforms-php5/trunk/src/pieform/elements/hidden.php 2006-12-23 03:48:43 UTC (rev 111) @@ -31,7 +31,7 @@ * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function pieform_render_hidden($element, Pieform $form) { +function pieform_element_hidden($element, Pieform $form) { $value = $form->get_value($element); if (is_array($value)) { $result = ''; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-23 03:48:04
|
Revision: 110 http://svn.sourceforge.net/pieforms/?rev=110&view=rev Author: oracleshinoda Date: 2006-12-22 19:48:02 -0800 (Fri, 22 Dec 2006) Log Message: ----------- Updated all rules to use the new i18n api Modified Paths: -------------- pieforms-php5/trunk/src/pieform/rules/email.php pieforms-php5/trunk/src/pieform/rules/maxlength.php pieforms-php5/trunk/src/pieform/rules/minlength.php pieforms-php5/trunk/src/pieform/rules/validateoptions.php Modified: pieforms-php5/trunk/src/pieform/rules/email.php =================================================================== --- pieforms-php5/trunk/src/pieform/rules/email.php 2006-12-23 03:47:04 UTC (rev 109) +++ pieforms-php5/trunk/src/pieform/rules/email.php 2006-12-23 03:48:02 UTC (rev 110) @@ -30,15 +30,24 @@ * Currently, the check is [anything]@[anything]. Someone is welcome to write * something better, this was made just for testing. * - * @param Pieform $form The form the rule is being applied to - * @param string $value The e-mail address to check - * @return string The error message, if there is something wrong with - * the address. + * @param Pieform $form The form the rule is being applied to + * @param string $value The e-mail address to check + * @param array $element The element to check + * @return string The error message, if there is something wrong with + * the address. */ -function pieform_rule_email(Pieform $form, $value) { +function pieform_rule_email(Pieform $form, $value, $element) { if (!preg_match('/^[a-z0-9\._%-]+@(?:[a-z0-9-]+\.)+[a-z]{2,4}$/', $value)) { - return $form->i18n('email'); + return $form->i18n('rule', 'email', 'email', $element); } } +function pieform_i18n_rule_email() { + return array( + 'en.utf8' => array( + 'email' => 'E-mail address is invalid' + ) + ); +} + ?> Modified: pieforms-php5/trunk/src/pieform/rules/maxlength.php =================================================================== --- pieforms-php5/trunk/src/pieform/rules/maxlength.php 2006-12-23 03:47:04 UTC (rev 109) +++ pieforms-php5/trunk/src/pieform/rules/maxlength.php 2006-12-23 03:48:02 UTC (rev 110) @@ -35,8 +35,16 @@ */ function pieform_rule_maxlength(Pieform $form, $value, $element, $maxlength) { if (strlen($value) > $maxlength) { - return sprintf($form->i18n('maxlength'), $maxlength); + return sprintf($form->i18n('rule', 'maxlength', 'maxlength', $element), $maxlength); } } +function pieform_i18n_rule_maxlength() { + return array( + 'en.utf8' => array( + 'maxlength' => 'This field must be at most %d characters long' + ) + ); +} + ?> Modified: pieforms-php5/trunk/src/pieform/rules/minlength.php =================================================================== --- pieforms-php5/trunk/src/pieform/rules/minlength.php 2006-12-23 03:47:04 UTC (rev 109) +++ pieforms-php5/trunk/src/pieform/rules/minlength.php 2006-12-23 03:48:02 UTC (rev 110) @@ -35,8 +35,16 @@ */ function pieform_rule_minlength(Pieform $form, $value, $element, $minlength) { if (strlen($value) < $minlength) { - return sprintf($form->i18n('minlength'), $minlength); + return sprintf($form->i18n('rule', 'minlength', 'minlength', $element), $minlength); } } +function pieform_i18n_rule_minlength() { + return array( + 'en.utf8' => array( + 'minlength' => 'This field must be at least %d characters long', + ) + ); +} + ?> Modified: pieforms-php5/trunk/src/pieform/rules/validateoptions.php =================================================================== --- pieforms-php5/trunk/src/pieform/rules/validateoptions.php 2006-12-23 03:47:04 UTC (rev 109) +++ pieforms-php5/trunk/src/pieform/rules/validateoptions.php 2006-12-23 03:48:02 UTC (rev 110) @@ -42,9 +42,17 @@ $allowedvalues = array_keys($element['options']); foreach ($field as $key) { if (!in_array($key, $allowedvalues)) { - return sprintf($form->i18n('validateoptions'), $key); + return sprintf($form->i18n('rule', 'validateoptions', 'validateoptions', $element), $key); } } } +function pieform_rule_validateoptions_i18n() { + return array( + 'en.utf8' => array( + 'validateoptions' => 'The option "%s" is invalid' + ) + ); +} + ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-23 03:47:07
|
Revision: 109 http://svn.sourceforge.net/pieforms/?rev=109&view=rev Author: oracleshinoda Date: 2006-12-22 19:47:04 -0800 (Fri, 22 Dec 2006) Log Message: ----------- Use new i18n API for required rule Modified Paths: -------------- pieforms-php5/trunk/src/pieform/rules/required.php Modified: pieforms-php5/trunk/src/pieform/rules/required.php =================================================================== --- pieforms-php5/trunk/src/pieform/rules/required.php 2006-12-23 03:46:16 UTC (rev 108) +++ pieforms-php5/trunk/src/pieform/rules/required.php 2006-12-23 03:47:04 UTC (rev 109) @@ -28,7 +28,7 @@ * Checks whether the field has been specified. * * @param Pieform $form The form the rule is being applied to - * @param string $field The field to check + * @param string $value The value of the field * @param array $element The element to check * @param string $check Whether to check the element * @return string The error message, if the value is invalid. @@ -38,15 +38,23 @@ $function = 'form_is_empty_' . $element['type']; if (function_exists($function)) { if ($function($value, $element)) { - return $form->i18n('required'); + return $form->i18n('rule', 'required', 'required', $element); } return; } if ($value == '') { - return $form->i18n('required'); + return $form->i18n('rule', 'required', 'required', $element); } } } +function pieform_rule_required_i18n() { + return array( + 'en.utf8' => array( + 'required' => 'This field is required' + ) + ); +} + ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-23 03:46:21
|
Revision: 108 http://svn.sourceforge.net/pieforms/?rev=108&view=rev Author: oracleshinoda Date: 2006-12-22 19:46:16 -0800 (Fri, 22 Dec 2006) Log Message: ----------- Use new i18n API for integer rule Modified Paths: -------------- pieforms-php5/trunk/src/pieform/rules/integer.php Modified: pieforms-php5/trunk/src/pieform/rules/integer.php =================================================================== --- pieforms-php5/trunk/src/pieform/rules/integer.php 2006-12-23 03:44:21 UTC (rev 107) +++ pieforms-php5/trunk/src/pieform/rules/integer.php 2006-12-23 03:46:16 UTC (rev 108) @@ -28,14 +28,23 @@ * Returns whether the given field is an integer * * @param Pieform $form The form the rule is being applied to - * @param string $value The value to check + * @param string $value The value to check + * @param array $element The element to check * @return string The error message, if there is something wrong with * the address. */ -function pieform_rule_integer(Pieform $form, $value) { +function pieform_rule_integer(Pieform $form, $value, $element) { if (!is_numeric($value) || $value != (int)$value) { - return $form->i18n('integer'); + return $form->i18n('rule', 'integer', 'integer', $element); } } +function pieform_i18n_rule_integer() { + return array( + 'en.utf8' => array( + 'integer' => 'The field must be an integer' + ) + ); +} + ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-23 03:44:21
|
Revision: 107 http://svn.sourceforge.net/pieforms/?rev=107&view=rev Author: oracleshinoda Date: 2006-12-22 19:44:21 -0800 (Fri, 22 Dec 2006) Log Message: ----------- Use new i18n API for regex rule Modified Paths: -------------- pieforms-php5/trunk/src/pieform/rules/regex.php Modified: pieforms-php5/trunk/src/pieform/rules/regex.php =================================================================== --- pieforms-php5/trunk/src/pieform/rules/regex.php 2006-12-23 03:39:29 UTC (rev 106) +++ pieforms-php5/trunk/src/pieform/rules/regex.php 2006-12-23 03:44:21 UTC (rev 107) @@ -36,8 +36,16 @@ */ function pieform_rule_regex(Pieform $form, $value, $element, $regex) { if (!preg_match($regex, $value)) { - return $form->i18n('regex'); + return $form->i18n('rule', 'regex', 'regex', $element); } } +function pieform_i18n_rule_regex() { + return array( + 'en.utf8' => array( + 'regex' => 'This field is not in valid form' + ) + ); +} + ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-23 03:39:29
|
Revision: 106 http://svn.sourceforge.net/pieforms/?rev=106&view=rev Author: oracleshinoda Date: 2006-12-22 19:39:29 -0800 (Fri, 22 Dec 2006) Log Message: ----------- Made the tablerenderer work again with the changes made recently. It now also correctly sets the error class on elements have an error on them Modified Paths: -------------- pieforms-php5/trunk/src/pieform/renderers/table.php Modified: pieforms-php5/trunk/src/pieform/renderers/table.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/table.php 2006-12-23 03:36:11 UTC (rev 105) +++ pieforms-php5/trunk/src/pieform/renderers/table.php 2006-12-23 03:39:29 UTC (rev 106) @@ -99,7 +99,7 @@ } function pieform_renderer_table_header() { - return "<table cellspacing=\"0\" border=\"0\"><tbody>\n"; + return "<table cellspacing=\"0\"><tbody>\n"; } function pieform_renderer_table_footer() { @@ -108,21 +108,13 @@ function pieform_renderer_table_messages_js($id) { $result = <<<EOF -// Given a message and form element name, should set an error on the element function {$id}_set_error(message, element) { - {$id}_remove_error(element); - element += '_container'; - // @todo set error class on input elements... - $(element).parentNode.insertBefore(TR({'id': '{$id}_error_' + element}, TD({'colspan': 2, 'class': 'errmsg'}, message)), $(element).nextSibling); + element = '{$id}_' + element + '_container'; + var container = getFirstElementByTagAndClassName('TD', null, $(element)); + addElementClass(container, 'error'); + addElementClass(container.firstChild, 'error'); + insertSiblingNodesAfter($(element), TR({'id': '{$id}_error_' + element}, TD({'colspan': 2, 'class': 'errmsg'}, message))); } -// Given a form element name, should remove an error associated with it -function {$id}_remove_error(element) { - element += '_container'; - var elem = $('{$id}_error_' + element); - if (elem) { - removeElement(elem); - } -} function {$id}_remove_all_errors() { forEach(getElementsByTagAndClassName('TD', 'errmsg', $('$id')), function(item) { removeElement(item.parentNode); @@ -134,8 +126,8 @@ if (elem) { swapDOM(elem, msg); } - else { - appendChildNodes($('{$id}_' + {$id}_btn + '_container').parentNode, msg); + else if ({$id}_btn) { + insertSiblingNodesAfter($('{$id}_' + {$id}_btn + '_container'), msg); } } function {$id}_remove_message() { @@ -144,7 +136,6 @@ removeElement(elem); } } - EOF; return $result; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-23 03:36:12
|
Revision: 105 http://svn.sourceforge.net/pieforms/?rev=105&view=rev Author: oracleshinoda Date: 2006-12-22 19:36:11 -0800 (Fri, 22 Dec 2006) Log Message: ----------- * Updated the comment on the Pieform class to better reflect the API changes being made * Only include the JSON library when json_encode is first called * Moved all of the user-configurable flags for the class into one member variable, 'data'. * Renamed the ajaxsuccessfunction and ajaxfailurefunction to *callback for consistency * Made the cancel function optional * Made setting $element['goto'] actually work, for both normal forms and AJAX forms * Fixed all submit-based elements to have their value placed in the submit data if they are pressed. * AJAX submission is now no longer strictly AJAX - instead, data is submitted to a hidden iframe. This removes all of the mess around the pieform_get_value_js_[element] functions, and allows sending files (which works fine, even for more than one file). * Now all replies by JSON should be done using the $form->json_reply method, which understands how to reply to a hidden iframe. * Defined some constants for use with $form->json_reply * Full i18n is now built in. Each element can export its own strings, and the user can override them on a per element or per form basis (even for all forms in their application with the pieform_configure function). * API changes: - Renamed pieform_configure_[element] to pieform_element_[element]_configure - Submit functions now take the Pieform object as their first parameter (major BC break!) - pieform_render_element now takes its parameters in reverse order (although this function is largely an internal-only function) - Renamed pieform_get_value_[element] to pieform_element_[element]_get_value - Renamed pieform_render_[element] to pieform_element_[element] (major BC break!) - pieform_element_[element] functions now takes the Pieform object as their first parameter (major BC break!) Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2006-12-18 01:12:20 UTC (rev 104) +++ pieforms-php5/trunk/src/pieform.php 2006-12-23 03:36:11 UTC (rev 105) @@ -37,22 +37,22 @@ * <pre> * $form = array( * 'name' => 'myform', - * 'action' => '/myscript.php', + * 'action' => 'myscript.php', * 'method' => 'post', * 'elements' => array( * // definition of elements in the form * ) * ); * - * $smarty->assign('myform', form($form)); + * $smarty->assign('myform', pieform($form)); * - * function myform_validate($form, $values) { + * function myform_validate(Pieform $form, $values) { * // perform validation agains form elements here * // some types of validation are conveniently available already as * // as part of the form definition hash * } * - * function myform_submit($values) { + * function myform_submit(Pieform $form, $values) { * // perform action knowing that the values are valid, e.g. DB insert. * } * </pre> @@ -66,22 +66,22 @@ // // @todo stuff to do for forms: // - // - more form element types (inc. types like autocomplete and date picker and wyswiyg) + // - more form element types (inc. types like autocomplete and wyswiyg) // - support processing of data before validation occurs (e.g. trim(), strtoupper()) // - Basic validation is possible as there's a callback function for checking, // but some helper functions could be written to make people's job validating // stuff much easier (form_validate_email, form_validate_date etc). // - Collapsible js for fieldsets // - Grippie for textareas - // - javascript validation + // - javascript validation (probably won't be done as ajax validation is pretty good) // - handle multipage forms? // - handle a tabbed interface type of form? // } if (!function_exists('json_encode')) { + require_once 'JSON/JSON.php'; function json_encode($data) { - require_once 'JSON/JSON.php'; $json = new Services_JSON(); return $json->encode($data); } @@ -96,24 +96,16 @@ * Represents an HTML form. Forms created using this class have a lot of the * legwork for forms abstracted away. * - * The form API makes it really easy to build complex HTML forms, simply by + * Pieforms makes it really easy to build complex HTML forms, simply by * building a hash describing your form, and defining one or two callback * functions. * - * For more information on how the form API works, please see the documentation + * For more information on how Pieforms works, please see the documentation * at https://eduforge.org/wiki/wiki/mahara/wiki?pagename=FormAPI */ class Pieform { /** - * Data for the form - * - * @var array - * @todo move all of the member fields here into this field - */ - private $data = array(); - - /** * Maintains a tab index across all created forms, to make it easy for * people to forget about it and have it just work for all of their forms. * @@ -129,131 +121,16 @@ private $name = ''; /** - * The method that the form will be submitted by. Either 'get' or 'post'. + * Data for the form * - * @var string - */ - private $method = 'get'; - - /** - * The URL that the form will be submitted to. - * - * @var string - */ - private $action = ''; - - /** - * Whether the form should be validated. Forms that are not validated are - * also not submitted. This is useful if you just want to draw a form, and - * have no validation rules apply to it. - */ - private $validate = true; - - /** - * Whether the form should be checked for submission. Forms can have - * validate on and submit off in order to validate submitted data, but to - * not bother with the submit. - * - * @var bool - */ - private $submit = true; - - /** - * Whether to submit the form via ajax - * - * @todo rename this probably, because AJAX GET is supported too - * - * @var bool - */ - private $ajaxpost = false; - - /** - * A callback to call before submitting the form via AJAX - * - * @var string - */ - private $preajaxsubmitcallback = ''; - - /** - * A callback to call after submitting the form via AJAX, regardless of - * the result of the submission - * - * @var string - */ - private $postajaxsubmitcallback = ''; - - /** - * Name of a javascript function to call on successful ajax submission - * - * @var string - */ - private $ajaxsuccessfunction = ''; - - /** - * Name of a javascript function to call on failed ajax submission - * - * @var string - */ - private $ajaxfailurefunction = ''; - - /** - * The tab index for this particular form. - * - * @var int - */ - private $tabindex = 1; - - /** - * Directories to look for elements, renderers and rules - * * @var array */ - private $configdirs = array(); + private $data = array(); /** - * Whether to autofocus fields in this form, and if so, optionally which - * field to focus. - * - * @var mixed - */ - private $autofocus = false; - - /** - * The renderer used to build the HTML for the form that each element sits - * in. See the form/renderer package to find out the allowed types. - * - * @var string - */ - private $renderer = 'table'; - - /** - * The language used for form rule error messages. - * - * @var string - */ - private $language = 'en.utf8'; - - /** - * Language strings for rules - * - * @var array - */ - private $language_strings = array( - 'en.utf8' => array( - 'required' => 'This field is required', - 'email' => 'E-mail address is invalid', - 'maxlength' => 'This field must be at most %d characters long', - 'minlength' => 'This field must be at least %d characters long', - 'integer' => 'The field must be an integer', - 'validateoptions' => 'The option "%s" is invalid', - 'regex' => 'This field is not in valid form' - ) - ); - - /** * Whether this form includes a file element. If so, the enctype attribute * for the form will be specified as "multipart/mixed" as required. This - * is auto-detected by the Form class. + * is auto-detected by the Pieform class. * * @var bool */ @@ -268,30 +145,6 @@ private $submitted = false; /** - * Whether the form is cancellable or not - that is, whether sending a - * request to cancel the form will be honoured or not. This is useful for - * the transient login form, where it must pass on cancel requests from - * other forms sometimes. - * - * @var bool - */ - private $iscancellable = true; - - /** - * Name of validate function - * - * @var string - */ - private $validatefunction = ''; - - /** - * Name of submit function - * - * @var string - */ - private $submitfunction = ''; - - /** * Processes the form. Called by the {@link pieform} function. It simply * builds the form (processing it if it has been submitted), and returns * the HTML to display the form @@ -335,101 +188,81 @@ // Assign defaults for the form $formdefaults = array( - 'method' => 'get', - 'action' => '', - 'ajaxpost' => false, + 'method' => 'get', + 'action' => '', + 'elements' => array(), + 'renderer' => 'table', + 'ajaxform' => false, 'preajaxsubmitcallback' => '', 'postajaxsubmitcallback' => '', - 'ajaxsuccessfunction' => '', - 'ajaxfailurefunction' => '', - 'configdirs' => array(), - 'autofocus' => false, - 'language' => 'en.utf8', + 'ajaxsuccesscallback' => '', + 'ajaxfailurecallback' => '', 'validate' => true, 'submit' => true, - 'elements' => array(), - 'submitfunction' => '', - 'validatefunction' => '', + 'validatecallback' => '', + 'submitcallback' => '', + 'iscancellable' => true, + 'autofocus' => false, + 'configdirs' => array(), + 'language' => 'en.utf8', + 'rulei18n' => array(), + 'tabindex' => false ); $data = array_merge($formdefaults, $formconfig, $data); $this->data = $data; // Set the method - only get/post allowed - $data['method'] = strtolower($data['method']); - if ($data['method'] != 'post') { - $data['method'] = 'get'; + $this->data['method'] = strtolower($data['method']); + if ($this->data['method'] != 'post') { + $this->data['method'] = 'get'; } - $this->method = $data['method']; - $this->action = $data['action']; - $this->validate = $data['validate']; - $this->submit = $data['submit']; - $this->configdirs = array_map( - create_function('$a', 'return substr($a, -1) == "/" ? substr($a, 0, -1) : $a;'), - (array) $data['configdirs']); - $this->autofocus = $data['autofocus']; - $this->language = $data['language']; - - if ($data['submitfunction']) { - $this->submitfunction = $data['submitfunction']; - } - else { - $this->submitfunction = $this->name . '_submit'; - } - if ($data['validatefunction']) { - $this->validatefunction = $data['validatefunction']; + // Make sure that the javascript callbacks are valid + if ($this->data['ajaxform']) { + $this->validate_js_callbacks(); } - else { - $this->validatefunction = $this->name . '_validate'; - } - if ($data['ajaxpost']) { - $this->ajaxpost = true; - $this->preajaxsubmitcallback = self::validate_js_callback($data['preajaxsubmitcallback']); - $this->postajaxsubmitcallback = self::validate_js_callback($data['postajaxsubmitcallback']); - // @todo rename to *callback instead of *function for consistency - $this->ajaxsuccessfunction = self::validate_js_callback($data['ajaxsuccessfunction']); - $this->ajaxfailurefunction = self::validate_js_callback($data['ajaxfailurefunction']); + if (!$this->data['validatecallback']) { + $this->data['validatecallback'] = $this->name . '_validate'; } - if (isset($data['renderer'])) { - $this->renderer = $data['renderer']; + if (!$this->data['submitcallback']) { + $this->data['submitcallback'] = $this->name . '_submit'; } - if (isset($data['tabindex'])) { - $this->tabindex = intval($data['tabindex']); - } - else { - $this->tabindex = self::$formtabindex++; - } + $this->data['configdirs'] = array_map( + create_function('$a', 'return substr($a, -1) == "/" ? substr($a, 0, -1) : $a;'), + (array) $this->data['configdirs']); - $this->iscancellable = (isset($data['iscancellable']) && !$data['iscancellable']) ? false : true; - if (!is_array($data['elements']) || count($data['elements']) == 0) { + if (empty($this->data['tabindex'])) { + $this->data['tabindex'] = self::$formtabindex++; + } + + if (!is_array($this->data['elements']) || count($this->data['elements']) == 0) { throw new PieformException('Forms must have a list of elements'); } // Remove elements to ignore - foreach ($data['elements'] as $name => $element) { + foreach ($this->data['elements'] as $name => $element) { if (isset($element['type']) && $element['type'] == 'fieldset') { foreach ($element['elements'] as $subname => $subelement) { if (!empty($subelement['ignore'])) { - unset ($data['elements'][$name]['elements'][$subname]); + unset ($this->data['elements'][$name]['elements'][$subname]); } } } else { if (!empty($element['ignore'])) { - unset($data['elements'][$name]); + unset($this->data['elements'][$name]); } } } - $this->elements = $data['elements']; - // Set some attributes for all elements $autofocusadded = false; - foreach ($this->elements as $name => &$element) { + foreach ($this->data['elements'] as $name => &$element) { + // @todo re-check ordering of this section // The name can be in the element itself. This is compatibility for the perl version if (isset($element['name'])) { $name = $element['name']; @@ -449,12 +282,13 @@ } if ($element['type'] == 'file') { $this->fileupload = true; - if ($this->method == 'get') { - $this->method = 'post'; + if ($this->data['method'] == 'get') { + $this->data['method'] = 'post'; self::info("Your form '$this->name' had the method 'get' and also a file element - it has been converted to 'post'"); } } if ($element['type'] == 'fieldset') { + $this->include_plugin('element', 'fieldset'); foreach ($element['elements'] as $subname => &$subelement) { // The name can be in the element itself. This is compatibility for the perl version if (isset($subelement['name'])) { @@ -470,32 +304,12 @@ . $name . '" has no value'); } } - if (!isset($subelement['title'])) { - $subelement['title'] = ''; - } - if ($subelement['type'] == 'file') { - $this->fileupload = true; - if ($this->method == 'get') { - $this->method = 'post'; - self::info("Your form '$this->name' had the method 'get' and also a file element - it has been converted to 'post'"); - } - } - if (!$autofocusadded && $this->autofocus === true) { - $subelement['autofocus'] = true; - $autofocusadded = true; - } - else if (!empty($this->autofocus) && $this->autofocus !== true - && $subname == $this->autofocus) { - $subelement['autofocus'] = true; - } - $subelement['name'] = $subname; - $subelement['tabindex'] = $this->tabindex; - // Let each element set and override attributes if necessary + // Configure some basics for real elements 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']; + $function = 'pieform_element_' . $subelement['type'] . '_configure'; if (function_exists($function)) { $subelement = $function($subelement); } @@ -503,65 +317,100 @@ // 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'; + $function = 'pieform_element_' . $subelement['type'] . '_set_attributes'; $this->include_plugin('element', $subelement['type']); if (function_exists($function)) { $subelement = $function($subelement); } + + // Add the autofocus flag to the element if required + if (!$autofocusadded && $this->data['autofocus'] === true && empty($element['nofocus'])) { + $subelement['autofocus'] = true; + $autofocusadded = true; + } + else if (!empty($this->data['autofocus']) && $this->data['autofocus'] !== true + && $subname == $this->data['autofocus']) { + $subelement['autofocus'] = true; + } + + // All elements should have some kind of title + if (!isset($subelement['title'])) { + $subelement['title'] = ''; + } + + // Force the form method to post if there is a file to upload. + if ($subelement['type'] == 'file') { + $this->fileupload = true; + if ($this->data['method'] == 'get') { + $this->data['method'] = 'post'; + self::info("Your form '$this->name' had the method 'get' and also a file element - it has been converted to 'post'"); + } + } + + // All elements inherit the form tabindex + $subelement['tabindex'] = $this->data['tabindex']; } + $subelement['name'] = $subname; + } } else { - if (!$autofocusadded && $this->autofocus === true) { - $element['autofocus'] = true; - $autofocusadded = true; - } - elseif (!empty($this->autofocus) && $this->autofocus !== true - && $name == $this->autofocus) { - $element['autofocus'] = true; - } - $element['name'] = $name; - $element['tabindex'] = $this->tabindex; - } + // Let each element set and override attributes if necessary + if ($element['type'] != 'markup') { + $function = 'pieform_element_' . $element['type'] . '_configure'; + if (function_exists($function)) { + $element = $function($element); + } - // 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_element_' . $element['type'] . '_set_attributes'; + $this->include_plugin('element', $element['type']); + if (function_exists($function)) { + $element = $function($element); + } - $function = 'pieform_render_' . $element['type'] . '_set_attributes'; - $this->include_plugin('element', $element['type']); - if (function_exists($function)) { - $element = $function($element); + // Add the autofocus flag to the element if required + if (!$autofocusadded && $this->data['autofocus'] === true && empty($element['nofocus'])) { + $element['autofocus'] = true; + $autofocusadded = true; + } + elseif (!empty($this->data['autofocus']) && $this->data['autofocus'] !== true + && $name == $this->data['autofocus']) { + $element['autofocus'] = true; + } + + $element['tabindex'] = $this->data['tabindex']; } + $element['name'] = $name; } + } // Check if the form was submitted, and if so, validate and process it - $global = ($this->method == 'get') ? $_GET: $_POST; - if ($this->validate && isset($global['pieform_' . $this->name] )) { - if ($this->submit) { + $global = ($this->data['method'] == 'get') ? $_GET: $_POST; + if ($this->data['validate'] && isset($global['pieform_' . $this->name] )) { + if ($this->data['submit']) { $this->submitted = true; // Check if the form has been cancelled - if ($this->iscancellable) { + if ($this->data['iscancellable']) { foreach ($global as $key => $value) { if (substr($key, 0, 7) == 'cancel_') { - // Check for and call the cancel function handler - // @todo<nigel>: it might be that this function could be optional + // Check for and call the cancel function handler, if defined $function = $this->name . '_' . $key; - if (!function_exists($function)) { - throw new PieformException('Form "' . $this->name . '" does not have a cancel function handler for "' . substr($key, 7) . '"'); + if (function_exists($function)) { + $function($this); } - $function(); + + // Redirect the user to where they should go, if the cancel handler didn't already $element = $this->get_element(substr($key, 7)); if (!isset($element['goto'])) { throw new PieformException('Cancel element "' . $element['name'] . '" has no page to go to'); } - // @todo what happens in the case of ajax post? - redirect($element['goto']); - return; + if ($this->data['ajaxform']) { + $this->json_reply(PIEFORM_CANCEL, $element['goto']); + } + header('HTTP/1.1 303 See Other'); + header('Location:' . $element['goto']); + exit; } } } @@ -572,32 +421,32 @@ // Perform general validation first $this->validate($values); // Then user specific validation if a function is available for that - if (function_exists($this->validatefunction)) { - $function = $this->validatefunction; + $function = $this->data['validatecallback']; + if (function_exists($function)) { $function($this, $values); } // Submit the form if things went OK - if ($this->submit && !$this->has_errors()) { + if ($this->data['submit'] && !$this->has_errors()) { $submitted = false; foreach ($this->get_elements() as $element) { // @todo Rename 'ajaxmessages' to 'submitelement' if (!empty($element['ajaxmessages']) == true && isset($global[$element['name']])) { $function = "{$this->name}_submit_{$element['name']}"; if (function_exists($function)) { - $function($values); + $function($this, $values); $submitted = true; break; } } } - if (!$submitted && function_exists($this->submitfunction)) { - $function = $this->submitfunction; + $function = $this->data['submitcallback']; + if (!$submitted && function_exists($function)) { // Call the user defined function for processing a submit // This function should really redirect/exit after it has // finished processing the form. // @todo maybe it should do just that... - $function($values); + $function($this, $values); // This will only work if I can make the login_submit function stuff work in login_validate //if ($this->ajaxpost) { // $message = 'Your ' . $this->name . '_submit function should output some json and exit'; @@ -613,19 +462,18 @@ } // Auto focus the first element with an error if required - if ($this->autofocus !== false) { + if ($this->data['autofocus'] !== false) { $this->auto_focus_first_error(); } // If the form has been submitted by ajax, return ajax - if ($this->ajaxpost) { + if ($this->data['ajaxform']) { $errors = $this->get_errors(); $json = array(); foreach ($errors as $element) { $json[$element['name']] = $element['error']; } - echo json_encode(array('error' => 'local', 'message' => '@todo allow forms to specify a local error message', 'errors' => $json)); - exit; + $this->json_reply(PIEFORM_ERR, '@todo allow forms to specify a local error message', $json); } } } @@ -652,33 +500,15 @@ } /** - * Returns the form submission method + * Returns whether the form has been submitted * - * @return string - */ - public function get_method() { - return $this->method; - } - - /** - * Is the form being submitted by ajax? - * * @return bool */ - public function get_ajaxpost() { - return $this->ajaxpost; + public function is_submitted() { + return $this->submitted; } /** - * Returns the renderer used on to render the form - * - * @return string - */ - public function get_renderer() { - return $this->renderer; - } - - /** * Returns the HTML for the <form...> tag * * @return string @@ -686,7 +516,7 @@ public function get_form_tag() { $result = '<form'; foreach (array('name', 'method', 'action') as $attribute) { - $result .= ' ' . $attribute . '="' . $this->{$attribute} . '"'; + $result .= ' ' . $attribute . '="' . $this->data[$attribute] . '"'; } $result .= ' id="' . $this->name . '"'; if ($this->fileupload) { @@ -697,15 +527,6 @@ } /** - * Returns whether the form has been submitted - * - * @return bool - */ - public function is_submitted() { - return $this->submitted; - } - - /** * Builds and returns the HTML for the form, respecting the chosen renderer. * * Note that the "action" attribute for the form tag are NOT HTML escaped @@ -722,23 +543,23 @@ $result = $this->get_form_tag() . "\n"; } - $this->include_plugin('renderer', $this->renderer); + $this->include_plugin('renderer', $this->data['renderer']); // Form header - $function = 'pieform_renderer_' . $this->renderer . '_header'; + $function = 'pieform_renderer_' . $this->data['renderer'] . '_header'; if (function_exists($function)) { $result .= $function(); } // Render each element - foreach ($this->elements as $name => $elem) { + foreach ($this->data['elements'] as $name => $elem) { if ($elem['type'] != 'hidden') { - $result .= pieform_render_element($elem, $this); + $result .= pieform_render_element($this, $elem); } } // Form footer - $function = 'pieform_renderer_' . $this->renderer . '_footer'; + $function = 'pieform_renderer_' . $this->data['renderer'] . '_footer'; if (function_exists($function)) { $result .= $function(); } @@ -747,7 +568,7 @@ $this->include_plugin('element', 'hidden'); foreach ($this->get_elements() as $element) { if ($element['type'] == 'hidden') { - $result .= pieform_render_hidden($element, $this); + $result .= pieform_element_hidden($element, $this); } } $element = array( @@ -755,15 +576,15 @@ 'name' => 'pieform_' . $this->name, 'value' => '' ); - $result .= pieform_render_hidden($element, $this); + $result .= pieform_element_hidden($element, $this); if ($outputformtags) { $result .= "</form>\n"; } - if ($this->ajaxpost) { - $result .= '<script language="javascript" type="text/javascript">'; - $result .= $this->submit_js(); - $result .= "</script>\n"; + if ($this->data['ajaxform']) { + $result .= '<script type="text/javascript">'; + $result .= "\n" . $this->submit_js(); + $result .= "\n</script>\n"; } return $result; @@ -777,21 +598,17 @@ * is available for the element. */ public function get_value($element) { - $function = 'pieform_get_value_' . $element['type']; - // @todo for consistency, reverse parameter order - always a Form object first + $function = 'pieform_element_' . $element['type'] . '_get_value'; if (function_exists($function)) { - return $function($element, $this); + return $function($this, $element); } - $global = ($this->method == 'get') ? $_GET : $_POST; + $global = ($this->data['method'] == 'get') ? $_GET : $_POST; // If the element is a submit element and has its value in the request, return it // Otherwise, we don't return the value if the form has been submitted, as they // aren't normally returned using a standard form. - if (isset($element['value']) && !empty($element['ajaxmessages']) && isset($global[$element['name']])) { + if (isset($element['value'])) { return $element['value']; } - else if (isset($element['value']) && (!$this->is_submitted() || (empty($element['ajaxmessages'])))) { - return $element['value']; - } else if (isset($global[$element['name']]) && $element['type'] != 'submit') { return $global[$element['name']]; } @@ -810,7 +627,7 @@ */ public function get_elements() { $elements = array(); - foreach ($this->elements as $name => $element) { + foreach ($this->data['elements'] as $name => $element) { if ($element['type'] == 'fieldset') { foreach ($element['elements'] as $subelement) { $elements[] = $subelement; @@ -844,7 +661,7 @@ } /** - * Retrieves submitted values from POST for the elements of this form. + * Retrieves submitted values from the request for the elements of this form. * * This takes into account that some elements may not even have been set, * for example if they were check boxes that were not checked upon @@ -857,10 +674,14 @@ */ private function get_submitted_values() { $result = array(); - $global = ($this->method == 'get') ? $_GET : $_POST; + $global = ($this->data['method'] == 'get') ? $_GET : $_POST; + log_debug($global); foreach ($this->get_elements() as $element) { if ($element['type'] != 'markup') { - $result[$element['name']] = $this->get_value($element); + if (empty($element['ajaxmessages']) || + !empty($element['ajaxmessages']) && isset($global[$element['name']])) { + $result[$element['name']] = $this->get_value($element); + } } } return $result; @@ -901,132 +722,123 @@ } } - /** - * Returns a js function to submit an ajax form - * Expects formname_message() to be defined by the renderer, - * and formname_validate() to be defined. - */ private function submit_js() { - // @todo nigel should disable all buttons on this form while the submit is happening - $result = <<<EOF + $strprocessingform = get_string('processingform'); -var {$this->name}_btn = null; -// For each submit button, add a waffer thin flag -addLoadEvent(function () { + $result = "var {$this->name}_btn = null;\n"; -EOF; + $connecteventadded = false; foreach ($this->get_elements() as $element) { if (!empty($element['ajaxmessages'])) { - $result .= " connect($('{$this->name}_{$element['name']}'), 'onclick', function () { {$this->name}_btn = '{$element['name']}'; });\n"; + if (!$connecteventadded) { + $result .= "addLoadEvent(function() {\n"; + $connecteventadded = true; + } + $result .= " connect($('{$this->name}_{$element['name']}'), 'onclick', function() { {$this->name}_btn = '{$element['name']}'; });\n"; } } + if ($connecteventadded) { + $result .= "});\n"; + } + $result .= <<<EOF +connect($('{$this->name}'), 'onsubmit', function(e) { + if (typeof(tinyMCE) != 'undefined') { tinyMCE.triggerSave(); } -}); - -connect($('{$this->name}'), 'onsubmit', function (e) { - // eventually we should check input types for wysiwyg before doing this - // Also should only save wysiwyg elements in the form, not all of them... - if (typeof(tinyMCE) != 'undefined') { tinyMCE.triggerSave(); } - EOF; - if (!empty($this->preajaxsubmitcallback)) { - $result .= " $this->preajaxsubmitcallback();\n"; + if (!empty($this->data['preajaxsubmitcallback'])) { + $result .= " {$this->data['preajaxsubmitcallback']}();\n"; } $result .= <<<EOF - var data = {}; + var iframe = $('{$this->name}_iframe'); + $('{$this->name}').target = '{$this->name}_iframe'; + if (!iframe) { + iframe = createDOM('iframe', { + 'name': '{$this->name}_iframe', + 'id' : '{$this->name}_iframe' + }); + hideElement(iframe); + insertSiblingNodesAfter($('{$this->name}'), iframe); + + window.pieformHandler_{$this->name} = function(data) { + {$this->name}_remove_all_errors(); + evalJSONRequest(data); + if (data.returnCode == 0) { + // The request completed successfully + {$this->name}_message(data.message, 'ok'); + EOF; - // Get values for each element from the form via the DOM - foreach ($this->get_elements() as $element) { - // Submit elements will be handled later, as there could be more than one - if (empty($element['ajaxmessages'])) { - if ($element['type'] != 'markup') { - $function = 'pieform_get_value_js_' . $element['type']; - if (function_exists($function)) { - // @todo reverse parameter order for consistency, PieForm first - $result .= $function($element, $this); - } - else { - $result .= " data['" . $element['name'] . "'] = document.forms['$this->name'].elements['{$element['name']}'].value;\n"; - } - } - } + + if (!empty($this->data['ajaxsuccesscallback'])) { + $result .= " {$this->data['ajaxsuccesscallback']}(data);\n"; } - // Add only the submit button that was clicked - $result .= " data[{$this->name}_btn] = document.forms['$this->name'].elements['{$this->name}_' + {$this->name}_btn].value;\n"; - // Add the hidden element for detecting form submission - $result .= " data['pieform_{$this->name}'] = '';\n"; - - $action = ($this->action) ? $this->action : basename($_SERVER['PHP_SELF']); - $method = ($this->get_method() == 'get') ? 'GET' : 'POST'; $result .= <<<EOF - var req = getXMLHttpRequest(); - req.open('{$method}', '{$action}'); - req.setRequestHeader('Content-type','application/x-www-form-urlencoded'); - var d = sendXMLHttpRequest(req,queryString(data)); - d.addCallbacks( - function (result) { - {$this->name}_remove_all_errors(); - var data = evalJSONRequest(result); - if (data.error) { - {$this->name}_message(data.message, 'error'); - for (error in data.errors) { - {$this->name}_set_error(data.errors[error], error); } + else if (data.returnCode == 1) { + // The request failed validation + {$this->name}_message(data.message, 'error'); + for (error in data.errors) { + {$this->name}_set_error(data.errors[error], error); + } EOF; - if (!empty($this->ajaxfailurefunction)) { - $result .= " {$this->ajaxfailurefunction}(data);\n"; + if (!empty($this->data['ajaxfailurecallback'])) { + $result .= " {$this->data['ajaxfailurecallback']}(data);\n"; } $result .= <<<EOF - } - else { - {$this->name}_message(data.message, 'ok'); + } + else if (data.returnCode == 2) { + window.location = data.message; + } + else { + // A return code we don't know about + // @todo call some predefined function passing the data + alert('an unknown error occured (if you are a mahara dev, see Nigel)'); + } EOF; - - if (!empty($this->ajaxsuccessfunction)) { - $result .= " {$this->ajaxsuccessfunction}(data);\n"; + if (!empty($this->data['postajaxsubmitcallback'])) { + $result .= " {$this->data['postajaxsubmitcallback']}();\n"; } - $result .= " {$this->name}_remove_all_errors();\n"; - $result .= " }\n"; - if (!empty($this->postajaxsubmitcallback)) { - $result .= " $this->postajaxsubmitcallback();\n"; + $result .= <<<EOF } + } - $strunknownerror = $this->i18n('ajaxunknownerror'); - $strprocessingform = $this->i18n('processingform'); - $result .= <<<EOF - }, - function() { - {$this->name}_message('{$strunknownerror}', 'error'); + if ({$this->name}_btn) { + {$this->name}_message('{$strprocessingform}', 'info'); + } +}); + EOF; - if (!empty($this->postajaxsubmitcallback)) { - $result .= " $this->postajaxsubmitcallback();\n"; + $function = 'pieform_renderer_' . $this->data['renderer'] . '_messages_js'; + if (!function_exists($function)) { + throw new PieformException('No renderer message function "' . $function . '"'); } - $result .= <<<EOF - }); - {$this->name}_message('{$strprocessingform}', 'info'); - e.stop(); -}); -EOF; - - $js_messages_function = 'pieform_renderer_' . $this->renderer . '_messages_js'; - if (!function_exists($js_messages_function)) { - $this->include_plugin('renderer', $this->renderer); - if (!function_exists($js_messages_function)) { - throw new PieformException('No renderer message function "' . $js_messages_function . '"'); - } + return $result . $function($this->name); + } + + public function json_reply($returncode, $message=null, $errors=null) { + $data = array( + 'returnCode' => intval($returncode), + 'message' => $message + ); + if ($errors) { + $data['errors'] = $errors; } + $result = json_encode($data); + log_debug($result); - return $result . $js_messages_function($this->name); + echo <<<EOF +<html><head><script type="text/javascript">function sendResult() { parent.pieformHandler_{$this->name}($result); }</script></head><body onload="sendResult(); "></body></html> +EOF; + exit; } /** @@ -1066,7 +878,7 @@ * @throws PieformException If the element could not be found */ public function set_error($name, $message) { - foreach ($this->elements as &$element) { + foreach ($this->data['elements'] as &$element) { if ($element['type'] == 'fieldset') { foreach ($element['elements'] as &$subelement) { if ($subelement['name'] == $name) { @@ -1215,7 +1027,7 @@ } // Check the configured include paths if they are specified - foreach ($this->configdirs as $directory) { + foreach ($this->data['configdirs'] as $directory) { $file = "$directory/{$type}s/$name.php"; if (is_readable($file)) { include_once($file); @@ -1238,17 +1050,37 @@ * * Returns english by default. * - * @param string $key The language key to look up - * @return string The internationalised string + * @param string $plugin The type of plugin (element, renderer, rule) + * @param string $pluginname The name of the plugin to get the language + * strings for + * @param string $key The language key to look up + * @param array $element The element to get the string for. Elements + * can specify there own i18n strings for rules + * @return string The internationalised string */ - public function i18n($key) { - $function = 'pieform_' . $key . '_i18n'; - if (function_exists($function)) { - return $function($this->language); + public function i18n($plugin, $pluginname, $key, $element) { + if (!in_array($plugin, array('element', 'renderer', 'rule'))) { + throw new PieformException("Invalid plugin name '$plugin'"); } - if (isset($this->language_strings[$this->language][$key])) { - return $this->language_strings[$this->language][$key]; + + // Check the element itself for the language string + if ($plugin == 'rule' && isset($element['rulei18n'][$key])) { + return $element['rulei18n'][$key]; } + + // Check to see if a default was configured for the form + if ($plugin == 'rule' && isset($this->data['rulei18n'][$key])) { + return $this->data['rulei18n'][$key]; + } + + // Fall back to the default string + $function = 'pieform_' . $plugin . '_' . $pluginname . '_i18n'; + if (function_exists($function)) { + $strings = $function(); + return $strings[$this->data['language']][$key]; + } + + // We don't recognise this string return '[[' . $key . ']]'; } @@ -1277,14 +1109,16 @@ } } - private static function validate_js_callback($name) { - if ($name == '') { - return ''; + /** + * Makes sure that the ajax callbacks for this form are valid javascript + * function names. + */ + private function validate_js_callbacks() { + foreach (array('preajaxsubmitcallback', 'postajaxsubmitcallback', 'ajaxsuccesscallback', 'ajaxfailurecallback') as $callback) { + if ($this->data[$callback] != '' && !preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $this->data[$callback])) { + throw new PieformException("'{$this->data[$callback]}' is not a valid javascript callback name for callback '$callback'"); + } } - if (!preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $name)) { - throw new PieformException("'$name' is not a valid javascript callback name"); - } - return $name; } /** @@ -1308,7 +1142,7 @@ * an error on it */ private function auto_focus_first_error() { - foreach ($this->elements as &$element) { + foreach ($this->data['elements'] as &$element) { if ($element['type'] == 'fieldset') { foreach ($element['elements'] as &$subelement) { if (isset($subelement['error'])) { @@ -1343,37 +1177,27 @@ * {@internal This is separate so that child element types can nest other * elements inside them (like the fieldset element does for example).}} * - * @param array $element The element to render * @param Pieform $form The form to render the element for + * @param array $element The element to render * @return string The rendered element */ -function pieform_render_element($element, Pieform $form) { +function pieform_render_element(Pieform $form, $element) { // If the element is pure markup, don't pass it to the renderer if ($element['type'] == 'markup') { return $element['value'] . "\n"; } // Make sure that the function to render the element type is available - $function = 'pieform_render_' . $element['type']; + $function = 'pieform_element_' . $element['type']; - // Work out the renderer function required and make sure it exists - if ($renderer = $form->get_renderer()) { - $rendererfunction = 'pieform_renderer_' . $renderer; - if (!function_exists($rendererfunction)) { - $form->include_plugin('pieform/renderers/' . $renderer . '.php'); - if (!function_exists($rendererfunction)) { - throw new PieformException('No such form renderer: "' . $renderer . '"'); - } - } + $rendererfunction = 'pieform_renderer_' . $form->get_property('renderer'); + if (!function_exists($rendererfunction)) { + throw new PieformException('No such form renderer function: "' . $rendererfunction . '"'); } - else { - throw new PieformException('No form renderer specified for form "' . $form->get_name() . '"'); - } $element['id'] = Pieform::make_id($element); $element['class'] = Pieform::make_class($element); - // @todo reverse order of parameters for consistency, a Form object first - $builtelement = $function($element, $form); + $builtelement = $function($form, $element); // Remove the 'autofocus' class, because we only want it on the form input // itself, not the wrapping HTML @@ -1386,7 +1210,7 @@ $htmlelements = array(); foreach ($GLOBALS['_PIEFORM_REGISTRY'] as $form) { foreach ($form->get_elements() as $element) { - $function = 'pieform_get_headdata_' . $element['type']; + $function = 'pieform_element_' . $element['type'] . '_get_headdata'; if (function_exists($function)) { $elems = $function($element); $htmlelements = array_merge($htmlelements, $elems); @@ -1397,4 +1221,8 @@ return array_unique($htmlelements); } +define('PIEFORM_OK', 0); +define('PIEFORM_ERR', 1); +define('PIEFORM_CANCEL', 2); + ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-18 01:12:20
|
Revision: 104 http://svn.sourceforge.net/pieforms/?rev=104&view=rev Author: oracleshinoda Date: 2006-12-17 17:12:20 -0800 (Sun, 17 Dec 2006) Log Message: ----------- Make sure the multicolumntable renderer doesn't try to pass on nonexistant values Modified Paths: -------------- pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php Modified: pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php 2006-12-18 01:11:25 UTC (rev 103) +++ pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php 2006-12-18 01:12:20 UTC (rev 104) @@ -48,8 +48,8 @@ $formrenderermct->set_form($form); } -function pieform_renderer_multicolumntable_messages_js($id, $submitid) { - return pieform_renderer_table_messages_js($id, $submitid); +function pieform_renderer_multicolumntable_messages_js($id) { + return pieform_renderer_table_messages_js($id); } function pieform_renderer_multicolumntable_header() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-18 01:11:25
|
Revision: 103 http://svn.sourceforge.net/pieforms/?rev=103&view=rev Author: oracleshinoda Date: 2006-12-17 17:11:25 -0800 (Sun, 17 Dec 2006) Log Message: ----------- Actually make multiplebutton ajax submit work reasonably well now... Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2006-12-18 00:41:26 UTC (rev 102) +++ pieforms-php5/trunk/src/pieform.php 2006-12-18 01:11:25 UTC (rev 103) @@ -783,10 +783,13 @@ return $function($element, $this); } $global = ($this->method == 'get') ? $_GET : $_POST; - if (!empty($element['ajaxmessages']) && isset($global[$element['name']])) { + // If the element is a submit element and has its value in the request, return it + // Otherwise, we don't return the value if the form has been submitted, as they + // aren't normally returned using a standard form. + if (isset($element['value']) && !empty($element['ajaxmessages']) && isset($global[$element['name']])) { return $element['value']; } - if (isset($element['value'])) { + else if (isset($element['value']) && (!$this->is_submitted() || (empty($element['ajaxmessages'])))) { return $element['value']; } else if (isset($global[$element['name']]) && $element['type'] != 'submit') { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-18 00:41:31
|
Revision: 102 http://svn.sourceforge.net/pieforms/?rev=102&view=rev Author: oracleshinoda Date: 2006-12-17 16:41:26 -0800 (Sun, 17 Dec 2006) Log Message: ----------- Allowed the form tag to be retrieved separately from the rest of the form, which allows more flexibility in how the form is built. Hopefully fix up the passing of the submit value for ajax calls now as well Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2006-12-17 23:27:39 UTC (rev 101) +++ pieforms-php5/trunk/src/pieform.php 2006-12-18 00:41:26 UTC (rev 102) @@ -679,6 +679,24 @@ } /** + * Returns the HTML for the <form...> tag + * + * @return string + */ + public function get_form_tag() { + $result = '<form'; + foreach (array('name', 'method', 'action') as $attribute) { + $result .= ' ' . $attribute . '="' . $this->{$attribute} . '"'; + } + $result .= ' id="' . $this->name . '"'; + if ($this->fileupload) { + $result .= ' enctype="multipart/form-data"'; + } + $result .= '>'; + return $result; + } + + /** * Returns whether the form has been submitted * * @return bool @@ -695,20 +713,15 @@ * the other hand, this means you must be careful about escaping the URL, * especially if it has data from an external source in it. * + * @param boolean Whether to include the <form...></form> tags in the output * @return string The form as HTML */ - public function build() { - $result = '<form'; - foreach (array('name', 'method', 'action') as $attribute) { - $result .= ' ' . $attribute . '="' . $this->{$attribute} . '"'; + public function build($outputformtags=true) { + $result = ''; + if ($outputformtags) { + $result = $this->get_form_tag() . "\n"; } - $result .= ' id="' . $this->name . '"'; - if ($this->fileupload) { - $result .= ' enctype="multipart/form-data"'; - } - $result .= ">\n"; - // @todo masks attempts in pieform_render_element, including the error handling there $this->include_plugin('renderer', $this->renderer); // Form header @@ -743,7 +756,9 @@ 'value' => '' ); $result .= pieform_render_hidden($element, $this); - $result .= "</form>\n"; + if ($outputformtags) { + $result .= "</form>\n"; + } if ($this->ajaxpost) { $result .= '<script language="javascript" type="text/javascript">'; @@ -768,6 +783,9 @@ return $function($element, $this); } $global = ($this->method == 'get') ? $_GET : $_POST; + if (!empty($element['ajaxmessages']) && isset($global[$element['name']])) { + return $element['value']; + } if (isset($element['value'])) { return $element['value']; } @@ -934,7 +952,7 @@ } // Add only the submit button that was clicked - $result .= " data['{$this->name}_' + {$this->name}_btn] = document.forms['$this->name'].elements['{$this->name}_' + {$this->name}_btn].value;\n"; + $result .= " data[{$this->name}_btn] = document.forms['$this->name'].elements['{$this->name}_' + {$this->name}_btn].value;\n"; // Add the hidden element for detecting form submission $result .= " data['pieform_{$this->name}'] = '';\n"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-17 23:27:44
|
Revision: 101 http://svn.sourceforge.net/pieforms/?rev=101&view=rev Author: oracleshinoda Date: 2006-12-17 15:27:39 -0800 (Sun, 17 Dec 2006) Log Message: ----------- Use the new, smarter way of putting a message next to the correct submit button Modified Paths: -------------- pieforms-php5/trunk/src/pieform/renderers/table.php Modified: pieforms-php5/trunk/src/pieform/renderers/table.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/table.php 2006-12-17 23:26:45 UTC (rev 100) +++ pieforms-php5/trunk/src/pieform/renderers/table.php 2006-12-17 23:27:39 UTC (rev 101) @@ -106,7 +106,7 @@ return "</tbody></table>\n"; } -function pieform_renderer_table_messages_js($id, $submitid) { +function pieform_renderer_table_messages_js($id) { $result = <<<EOF // Given a message and form element name, should set an error on the element function {$id}_set_error(message, element) { @@ -135,7 +135,7 @@ swapDOM(elem, msg); } else { - appendChildNodes($('{$id}_{$submitid}_container').parentNode, msg); + appendChildNodes($('{$id}_' + {$id}_btn + '_container').parentNode, msg); } } function {$id}_remove_message() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-17 23:26:46
|
Revision: 100 http://svn.sourceforge.net/pieforms/?rev=100&view=rev Author: oracleshinoda Date: 2006-12-17 15:26:45 -0800 (Sun, 17 Dec 2006) Log Message: ----------- Use the new, smarter way of putting messages next to the correct submit button. Also, use some of the nicer new MochiKit methods to insert divs before/after others Modified Paths: -------------- pieforms-php5/trunk/src/pieform/renderers/div.php Modified: pieforms-php5/trunk/src/pieform/renderers/div.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/div.php 2006-12-17 23:24:49 UTC (rev 99) +++ pieforms-php5/trunk/src/pieform/renderers/div.php 2006-12-17 23:26:45 UTC (rev 100) @@ -77,16 +77,18 @@ return $result; } -function pieform_renderer_div_messages_js($id, $submitid) { + +// @todo needs updating again... need to replace remove_error with remove_all_errors +function pieform_renderer_div_messages_js($id) { $result = <<<EOF + // Given a message and form element name, should set an error on the element function {$id}_set_error(message, element) { {$id}_remove_error(element); element += '_container'; // @todo set error class on input elements... - $(element).parentNode.insertBefore(DIV({'id': '{$id}_error_' + element, 'class': 'errmsg'}, message), $(element).nextSibling); + insertSiblingNodesBefore(DIV({'id': '{$id}_error_' + element, 'class': 'errmsg'}, message), $(element)); } -// Given a form element name, should remove an error associated with it function {$id}_remove_error(element) { element += '_container'; var elem = $('{$id}_error_' + element); @@ -95,13 +97,13 @@ } } function {$id}_message(message, type) { - var elem = $('{$id}_message'); - var msg = DIV({'id': '{$id}_message', 'class': type}, message); + var elem = $('{$id}_pieform_message'); + var msg = DIV({'id': '{$id}_pieform_message', 'class': type}, message); if (elem) { swapDOM(elem, msg); } else { - appendChildNodes($('{$submitid}_container').parentNode, msg); + insertSiblingNodesAfter($('{$id}_' + {$id}_btn + '_container'), msg); } } function {$id}_remove_message() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2006-12-17 23:24:50
|
Revision: 99 http://svn.sourceforge.net/pieforms/?rev=99&view=rev Author: oracleshinoda Date: 2006-12-17 15:24:49 -0800 (Sun, 17 Dec 2006) Log Message: ----------- Be much smarter about which submit button is being sent through in ajax land. This prevents problems with all buttons being sent through and thus causing hiccups with the choice of submit function to call. It also conveniently makes sure that the status messages will always be displayed next to the correct button Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2006-12-15 01:30:15 UTC (rev 98) +++ pieforms-php5/trunk/src/pieform.php 2006-12-17 23:24:49 UTC (rev 99) @@ -889,6 +889,20 @@ // @todo nigel should disable all buttons on this form while the submit is happening $result = <<<EOF +var {$this->name}_btn = null; +// For each submit button, add a waffer thin flag +addLoadEvent(function () { + +EOF; + foreach ($this->get_elements() as $element) { + if (!empty($element['ajaxmessages'])) { + $result .= " connect($('{$this->name}_{$element['name']}'), 'onclick', function () { {$this->name}_btn = '{$element['name']}'; });\n"; + } + } + $result .= <<<EOF + +}); + connect($('{$this->name}'), 'onsubmit', function (e) { // eventually we should check input types for wysiwyg before doing this // Also should only save wysiwyg elements in the form, not all of them... @@ -904,24 +918,23 @@ EOF; // Get values for each element from the form via the DOM foreach ($this->get_elements() as $element) { - if ($element['type'] != 'markup') { - $function = 'pieform_get_value_js_' . $element['type']; - if (function_exists($function)) { - // @todo reverse parameter order for consistency, PieForm first - $result .= $function($element, $this); + // Submit elements will be handled later, as there could be more than one + if (empty($element['ajaxmessages'])) { + if ($element['type'] != 'markup') { + $function = 'pieform_get_value_js_' . $element['type']; + if (function_exists($function)) { + // @todo reverse parameter order for consistency, PieForm first + $result .= $function($element, $this); + } + else { + $result .= " data['" . $element['name'] . "'] = document.forms['$this->name'].elements['{$element['name']}'].value;\n"; + } } - else { - $result .= " data['" . $element['name'] . "'] = document.forms['$this->name'].elements['{$element['name']}'].value;\n"; - } - if (!empty($element['ajaxmessages'])) { - $messageelement = $element['name']; - } } } - if (!isset($messageelement)) { - throw new PieformException('At least one submit-type element is required for AJAX forms'); - } + // Add only the submit button that was clicked + $result .= " data['{$this->name}_' + {$this->name}_btn] = document.forms['$this->name'].elements['{$this->name}_' + {$this->name}_btn].value;\n"; // Add the hidden element for detecting form submission $result .= " data['pieform_{$this->name}'] = '';\n"; @@ -992,7 +1005,7 @@ } } - return $result . $js_messages_function($this->name, $messageelement); + return $result . $js_messages_function($this->name); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |