Commit 03c0111c authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files

Corrected the package and documentation for the rules. Removed the

redundant markup element type.
parent 140133a7
......@@ -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,11 @@
defined('INTERNAL') || die();
/**
* Renders a hidden element
* Renders a hidden 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_hidden($element, Form $form) {
unset($element['tabindex']);
......
<?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 form
* @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();
/**
* The simplest type of form element - pure markup.
*
* This can be used to add HTML at various points throughtout a form. However,
* this should NOT be used for anything other than basic formatting - please
* use CSS instead.
*
* If it's required, I will add support for theming forms which will allow
* radical changes to the output.
*/
function form_render_markup($element, $form) {
if (isset($element['value'])) {
return $element['value'];
}
return '';
}
?>
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @subpackage form/renderer
* @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,12 @@ defined('INTERNAL') || die();
/**
* Default renderer - renders form elements inside <div>s.
*
* @param string $builtelement The element, already built
* @param array $rawelement The element in raw form, for looking up
* information about it.
* @return string The element rendered inside an appropriate
* container.
*/
function form_renderer_div($builtelement, $rawelement) {
// Set the class of the enclosing <div> to match that of the element
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @subpackage form/rule
* @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,16 @@
defined('INTERNAL') || die();
/**
* Returns whether the given field is a valid e-mail address.
*
* Currently, the check is [anything]@[anything]. Someone is welcome to write
* something better, this was made just for testing.
*
* @param string $address The e-mail address to check
* @return string The error message, if there is something wrong with
* the address.
*/
function form_rule_email($address) {
if (!preg_match('/(.*)@(.*)/', $address)) {
return get_string('E-mail address is invalid');
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @subpackage form/rule
* @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();
/**
* Checks whether the given value is longer than the allowed length.
*
* @param string $value The value to check
* @param int $maxlength The length to check for
* @return string The error message, if the value is invalid.
*/
function form_rule_maxlength($value, $maxlength) {
if (strlen($value) > $maxlength) {
return get_string('This field can only be ' . $maxlength . ' characters long');
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @subpackage form/rule
* @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();
/**
* Checks whether the given value is shorter than the allowed length.
*
* @param string $value The value to check
* @param int $minlength The length to check for
* @return string The error message, if the value is invalid.
*/
function form_rule_minlength($value, $minlength) {
if (strlen($value) < $minlength) {
return get_string('This field must be at least ' . $minlength . ' characters long');
......
......@@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage form
* @subpackage form/rule
* @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();
/**
* Checks whether the field has been specified.
*
* @param string $field The field to check
* @return string The error message, if the value is invalid.
*/
function form_rule_required($field) {
// The array test is for using the "required" rule on file elements
if ($field == '' || is_array($field) && !empty($field['error'])) {
return get_string('This field is required');
}
......
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