Commit 2359063a authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files

Added a stub for a wysiwyg element, and corrected the documentation for all

of the other elements.
parent 13c0de8f
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @subpackage form/element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
......@@ -27,7 +27,13 @@
defined('INTERNAL') || die();
/**
* Renders a submit button
* Renders a "cancel" button. Custom buttons are rendered nearly the same as
* normal submit buttons, only their name is changed (for use by the Form class
* internally).
*
* @param array $element The element to render
* @param Form $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_cancel($element, Form $form) {
return '<input type="submit"'
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @subpackage form/element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
......@@ -27,9 +27,13 @@
defined('INTERNAL') || die();
/**
* Provides a basic text field input.
* Provides a basic checkbox input.
*
* @param array $element The element to render
* @param Form $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_checkbox($element, $form) {
function form_render_checkbox($element, Form $form) {
$checked = false;
if (!empty($element['value'])) {
$checked = true;
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @subpackage form/element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
......@@ -27,9 +27,14 @@
defined('INTERNAL') || die();
/**
* Renders a fieldset
* 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 Form $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_fieldset($element, $form) {
function form_render_fieldset($element, Form $form) {
$result = "\n<fieldset>\n";
if (isset($element['legend'])) {
$result .= '<legend>' . hsc($element['legend']) . "</legend>\n";
......
......@@ -17,8 +17,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage core or plugintype/pluginname
* @author Your Name <you@example.org>
* @subpackage form/element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
......@@ -26,7 +26,14 @@
defined('INTERNAL') || die();
function form_render_file($element) {
/**
* Renders a basic HTML <input type="file"> element.
*
* @param array $element The element to render
* @param Form $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_file($element, Form $form) {
return '<input type="file"'
. Form::element_attributes($element) . '>';
}
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @subpackage form/element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
......@@ -28,6 +28,10 @@ defined('INTERNAL') || die();
/**
* Renders a password field
*
* @param array $element The element to render
* @param Form $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_password($element, $form) {
return '<input type="password"'
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @subpackage form/element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
......@@ -30,7 +30,8 @@ defined('INTERNAL') || die();
* Renders a set of radio buttons for a form
*
* @param array $element The element to render
* @param Form $form The form the element is being rendered on
* @param Form $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_radio($element, Form $form) {
if (!isset($element['options']) || !is_array($element['options']) || count($element['options']) < 1) {
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @subpackage form/element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
......@@ -26,7 +26,14 @@
defined('INTERNAL') || die();
function form_render_select($element, $form) {
/**
* Renders a dropdown list, including support for multiple choices.
*
* @param array $element The element to render
* @param Form $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_select($element, Form $form) {
if (!empty($element['multiple'])) {
$element['name'] .= '[]';
}
......@@ -66,7 +73,7 @@ function form_render_select($element, $form) {
$result .= "\t<option value=\"" . hsc($key) . "\"$selected>" . hsc($value) . "</option>\n";
}
$result .= "</select>\n";
$result .= '</select>';
return $result;
}
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @subpackage form/element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
......@@ -28,6 +28,10 @@ defined('INTERNAL') || die();
/**
* Renders a submit button
*
* @param array $element The element to render
* @param Form $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_submit($element, $form) {
return '<input type="submit"'
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @subpackage form/element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
......@@ -28,6 +28,10 @@ defined('INTERNAL') || die();
/**
* Provides a basic text field input.
*
* @param array $element The element to render
* @param Form $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_text($element, $form) {
return '<input type="text"'
......
......@@ -17,8 +17,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage core or plugintype/pluginname
* @author Your Name <you@example.org>
* @subpackage file/element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
......@@ -26,6 +26,13 @@
defined('INTERNAL') || die();
/**
* Renders a basic HTML <textarea> element.
*
* @param array $element The element to render
* @param Form $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_textarea($element, $form) {
$rows = $cols = $style = '';
if (isset($element['height'])) {
......
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage file/element
* @author Nigel McNie <nigel@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
/**
* Renders a textarea, but with extra javascript to turn it into a wysigyw
* textarea.
*
* Currently this is just a mirror of the textarea element, but it will change
* a bit later.
*
* @param array $element The element to render
* @param Form $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_textarea($element, $form) {
$rows = $cols = $style = '';
if (isset($element['height'])) {
$style .= 'height:' . $element['height'] . ';';
$rows = (intval($element['height'] > 0)) ? ceil(intval($element['height']) / 10) : 1;
}
elseif (isset($element['rows'])) {
$rows = $element['rows'];
}
else {
log_warn('No value for rows or height specified for textarea ' . $element['name']);
}
if (isset($element['width'])) {
$style .= 'width:' . $element['width'] . ';';
$cols = (intval($element['width'] > 0)) ? ceil(intval($element['width']) / 10) : 1;
}
elseif (isset($element['cols'])) {
$cols = $element['cols'];
}
else {
log_warn('No value for cols or width specified for textarea ' . $element['name']);
}
$element['style'] = (isset($element['style'])) ? $style . $element['style'] : $style;
return '<textarea'
. (($rows) ? ' rows="' . $rows . '"' : '')
. (($cols) ? ' cols="' . $cols . '"' : '')
. Form::element_attributes($element, array('maxlength', 'size'))
. '>' . hsc($form->get_value($element)) . '</textarea>';
}
?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment