Commit 394c42ae authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files

Changed form library to be upstream now. Nigel will maintain an svn

checkout for the moment.

Modified all forms to use the new one.
parent 80107977
......@@ -29,7 +29,7 @@ define('MENUITEM', 'account');
define('SUBMENUITEM', 'activityprefs');
require(dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php');
require_once('form.php');
require_once('pieforms/pieform.php');
$activitytypes = get_records('activity_type', 'admin', 0);
$notifications = plugins_installed('notification');
......@@ -72,7 +72,7 @@ $prefsform = array(
$smarty = smarty();
$smarty->assign('prefsdescr', get_string('prefsdescr', 'activity'));
$smarty->assign('form', form($prefsform));
$smarty->assign('form', pieform($prefsform));
$smarty->display('account/activity/preferences/index.tpl');
function activityprefs_submit($values) {
......
......@@ -29,7 +29,7 @@ define('MENUITEM', 'account');
define('SUBMENUITEM', 'accountprefs');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once('form.php');
require_once('pieforms/pieform.php');
// load up user preferences
$prefs = (object)($SESSION->get('accountprefs'));
......@@ -138,7 +138,7 @@ $prefsform = array(
$smarty = smarty();
$smarty->assign('form', form($prefsform));
$smarty->assign('form', pieform($prefsform));
$smarty->assign('INLINEJAVASCRIPT', "
function clearPasswords() {
$('oldpassword').value = '';
......@@ -147,7 +147,7 @@ function clearPasswords() {
}");
$smarty->display('account/index.tpl');
function accountprefs_validate(Form $form, $values) {
function accountprefs_validate(Pieform $form, $values) {
if ($values['oldpassword'] !== '') {
global $SESSION, $authtype, $authclass;
if (!call_static_method($authclass, 'authenticate_user_account', $SESSION->get('username'), $values['oldpassword'], $SESSION->get('institution'))) {
......
......@@ -28,7 +28,7 @@ define('INTERNAL',1);
define('ADMIN', 1);
define('MENUITEM','pageeditor');
require(dirname(dirname(__FILE__)).'/init.php');
require_once('form.php');
require_once('pieforms/pieform.php');
$sitepages = get_records('site_content');
$pageoptions = array();
......@@ -67,7 +67,7 @@ $f = array(
),
)
);
$form = form($f);
$form = pieform($f);
function editsitepage_submit($values) {
......
......@@ -29,14 +29,14 @@ define('ADMIN',1);
define('MENUITEM','siteoptions');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('form.php');
require_once('pieforms/pieform.php');
$langoptions = get_languages();
$themeoptions = get_themes();
$yesno = array(true => get_string('yes'),
false => get_string('no'));
$siteoptionform = form(array(
$siteoptionform = pieform(array(
'name' => 'siteoptions',
'ajaxpost' => true,
'elements' => array(
......
......@@ -31,7 +31,7 @@ define('ADMIN', 1);
define('MENUITEM', 'usermanagement');
define('SUBMENUITEM', 'adminusers');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('form.php');
require_once('pieforms/pieform.php');
$smarty = smarty();
// Get users who are currently administrators
......@@ -72,7 +72,7 @@ function adminusers_submit($values) {
redirect(get_config('wwwroot') . 'admin/usermanagement/adminusers.php');
}
$smarty->assign('adminusersform', form($form));
$smarty->assign('adminusersform', pieform($form));
$smarty->display('admin/usermanagement/adminusers.tpl');
?>
......@@ -31,7 +31,7 @@ define('ADMIN', 1);
define('MENUITEM', 'usermanagement');
define('SUBMENUITEM', 'staffusers');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('form.php');
require_once('pieforms/pieform.php');
$smarty = smarty();
// Get users who are currently staff
......@@ -71,7 +71,7 @@ function staffusers_submit($values) {
redirect(get_config('wwwroot') . 'admin/usermanagement/staffusers.php');
}
$smarty->assign('staffusersform', form($form));
$smarty->assign('staffusersform', pieform($form));
$smarty->display('admin/usermanagement/staffusers.tpl');
?>
......@@ -29,7 +29,7 @@ define('ADMIN', 1);
define('MENUITEM', 'usermanagement');
define('SUBMENUITEM', 'uploadcsv');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('form.php');
require_once('pieforms/pieform.php');
$institutions = get_records('institution');
foreach ($institutions as $name => $data) {
......@@ -82,10 +82,10 @@ $form = array(
* user. The data from a successful parsing is stored in the <var>$CVSDATA</var>
* array so it can be accessed by the submit function
*
* @param Form $form The form to validate
* @param array $values The values submitted
* @param Pieform $form The form to validate
* @param array $values The values submitted
*/
function uploadcsv_validate(Form $form, $values) {
function uploadcsv_validate(Pieform $form, $values) {
global $CSVDATA;
// Don't even start attempting to parse if there are previous errors
......@@ -178,13 +178,13 @@ function uploadcsv_submit($values) {
}
log_info('Inserted ' . count($CSVDATA) . ' records');
$SESSION->add_ok_msg('yo yo users added yo!');
$SESSION->add_ok_msg(get_string('uploadcsvusersaddedsuccessfully', 'admin'));
// @todo support relative URLs here
redirect(get_config('wwwroot') . 'admin/usermanagement/uploadcsv.php');
}
$smarty = smarty();
$smarty->assign('uploadcsvform', form($form));
$smarty->assign('uploadcsvform', pieform($form));
$smarty->display('admin/usermanagement/uploadcsv.tpl');
?>
......@@ -28,7 +28,7 @@ define('INTERNAL', 1);
define('MENUITEM', 'myprofile');
require(dirname(dirname(dirname(dirname(__FILE__)))) . '/init.php');
require_once('form.php');
require_once('pieforms/pieform.php');
safe_require('artefact', 'internal');
$element_list = call_static_method('ArtefactTypeProfile', 'get_all_fields');
......@@ -97,7 +97,7 @@ $elements['submit'] = array(
'value' => get_string('saveprofile','artefact.internal'),
);
$profileform = form(array(
$profileform = pieform(array(
'name' => 'profileform',
'plugintype' => 'artefact',
'pluginname' => 'internal',
......@@ -106,7 +106,7 @@ $profileform = form(array(
'elements' => $elements,
));
function profileform_validate(Form $form, $values) {
function profileform_validate(Pieform $form, $values) {
global $profilefields;
if (
......
......@@ -98,9 +98,9 @@ abstract class Auth {
* to specify any validation rules if they do not need to.
*
* @param array $values The submitted values for the form
* @param Form $form The form being validated
* @param Pieform $form The form being validated
*/
public static function validate_configuration_form(Form $form, $values) {
public static function validate_configuration_form(Pieform $form, $values) {
}
/**
......@@ -250,8 +250,9 @@ function auth_setup () {
// Build login form. If the form is submitted it will be handled here,
// and set $USER for us (this will happen when users hit a page and
// specify login data immediately
require_once('form.php');
$form = new Form(auth_get_login_form());
//require_once('form.php');
require_once('pieforms/pieform.php');
$form = new Pieform(auth_get_login_form());
if ($USER) {
return $USER;
}
......@@ -344,7 +345,7 @@ function auth_check_password_change() {
);
$smarty = smarty();
$smarty->assign('change_password_form', form($form));
$smarty->assign('change_password_form', pieform($form));
$smarty->display('change_password.tpl');
exit;
}
......@@ -355,10 +356,10 @@ function auth_check_password_change() {
*
* Change password will only be if a URL for it exists, or a function exists.
*
* @param Form $form The form to check
* @param array $values The values to check
* @param Pieform $form The form to check
* @param array $values The values to check
*/
function change_password_validate(Form $form, $values) {
function change_password_validate(Pieform $form, $values) {
global $USER;
// Get the authentication type for the user (based on the institution), and
......@@ -418,19 +419,19 @@ function change_password_submit($values) {
* As this function builds and validates a login form, it is possible that
* calling this may validate a user to be logged in.
*
* @param Form $form If specified, just build this form to get the HTML
* required. Otherwise, this function will build and
* validate the form itself.
* @param Pieform $form If specified, just build this form to get the HTML
* required. Otherwise, this function will build and
* validate the form itself.
* @access private
*/
function auth_draw_login_page($message=null, Form $form=null) {
function auth_draw_login_page($message=null, Pieform $form=null) {
global $USER, $SESSION;
if ($form != null) {
$loginform = get_login_form_js($form->build());
}
else {
require_once('form.php');
$loginform = get_login_form_js(form(auth_get_login_form()));
$loginform = get_login_form_js(pieform(auth_get_login_form()));
/*
* If $USER is set, the form was submitted even before being built.
* This happens when a user's session times out and they resend post
......@@ -655,11 +656,11 @@ function login_submit($values) {
* This is for validation of the configuration form that each authentication
* method exports
*
* @param Form $form The form to validate
* @param array $values The values submitted to check
* @param Pieform $form The form to validate
* @param array $values The values submitted to check
* @access private
*/
function auth_validate(Form $form, $values) {
function auth_validate(Pieform $form, $values) {
$class = 'Auth' . $values['method'];
safe_require('auth', $values['method'], 'lib.php', 'require_once');
call_static_method($class, 'validate_configuration_form', $form, $values);
......
......@@ -29,9 +29,9 @@ define('MENUITEM', 'mycontacts');
define('SUBMENUITEM', 'mygroups');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('form.php');
require_once('pieforms/pieform.php');
$creategroup = form(array(
$creategroup = pieform(array(
'name' => 'creategroup',
'method' => 'post',
'elements' => array(
......@@ -58,7 +58,7 @@ $creategroup = form(array(
),
));
function creategroup_validate(Form $form, $values) {
function creategroup_validate(Pieform $form, $values) {
global $USER;
$gid = get_field('usr_group', 'id', 'owner', $USER->id, 'name', $values['name']);
......
......@@ -29,7 +29,7 @@ define('MENUITEM', 'mycontacts');
define('SUBMENUITEM', 'mygroups');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('form.php');
require_once('pieforms/pieform.php');
$id = param_integer('id',null);
......@@ -41,7 +41,7 @@ if (!$group_data) {
$group_members = get_column('usr_group_member', 'member', 'grp', $group_data->id);
$editgroup = form(array(
$editgroup = pieform(array(
'name' => 'editgroup',
'method' => 'post',
'elements' => array(
......@@ -75,7 +75,7 @@ $editgroup = form(array(
),
));
function editgroup_validate(Form $form, $values) {
function editgroup_validate(Pieform $form, $values) {
global $USER;
global $SESSION;
......
......@@ -74,7 +74,7 @@ if (isset($_GET['key'])) {
);
$smarty = smarty();
$smarty->assign('forgotpasschange_form', form($form));
$smarty->assign('forgotpasschange_form', pieform($form));
$smarty->display('forgotpass.tpl');
exit;
}
......@@ -101,7 +101,7 @@ $form = array(
)
);
function forgotpass_validate(Form $form, $values) {
function forgotpass_validate(Pieform $form, $values) {
// The e-mail address cannot already be in the system
if (!$form->get_error('email') && !($user = get_record('usr', 'email', $values['email']))) {
$form->set_error('email', get_string('forgotpassnosuchemailaddress'));
......@@ -150,7 +150,7 @@ function forgotpass_submit($values) {
redirect(get_config('wwwroot') . 'forgotpass.php');
}
function forgotpasschange_validate(Form $form, $values) {
function forgotpasschange_validate(Pieform $form, $values) {
if (!$user = get_record('usr', 'id', $values['user'])) {
throw new Exception('Request to change the password for a user who does not exist');
}
......@@ -197,7 +197,7 @@ function forgotpasschange_submit($values) {
}
$smarty = smarty();
$smarty->assign('forgotpass_form', form($form));
$smarty->assign('forgotpass_form', pieform($form));
$smarty->display('forgotpass.tpl');
?>
......@@ -33,8 +33,9 @@ require('init.php');
// Check for whether the user is logged in, before processing the page. After
// this, we can guarantee whether the user is logged in or not for this page.
if (!$SESSION->is_logged_in()) {
require_once('form.php');
$loginform = get_login_form_js(form(array(
//require_once('form.php');
require_once('pieforms/pieform.php');
$loginform = get_login_form_js(pieform(array(
'name' => 'login',
'renderer' => 'div',
'submit' => false,
......
......@@ -134,6 +134,7 @@ $string['uploadcsverroruseralreadyexists'] = 'Line %s of the file specifies the
$string['uploadcsv'] = 'Add Users by CSV';
$string['uploadcsvfile'] = 'Upload CSV File';
$string['uploadcsvfiledescription'] = 'You may use this facility to upload new users via a <acronym title="Comma Separated Values">CSV</acronym> file. Each record in the file must have a username, e-mail address and password.';
$string['uploadcsvusersaddedsuccessfully'] = 'The users in the file have been added successfully';
// Admin Users
$string['adminusers'] = 'Admin Users';
......
......@@ -1260,12 +1260,15 @@ function rebuild_artefact_parent_cache_complete() {
/**
* Configures a default form
*/
function form_configure() {
function pieform_configure() {
global $SESSION;
return array(
'method' => 'post',
'action' => '',
'autofocus' => true,
'renderer' => 'maharatable',
'preajaxsubmitcallback' => 'processingStart',
'postajaxsubmitcallback' => 'processingStop',
'elements' => array(
'sesskey' => array(
'type' => 'hidden',
......
This diff is collapsed.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
MochiKit is dual-licensed software. It is available under the terms of the
MIT License, or the Academic Free License version 2.1. The full text of
each license is included below.
MIT License
===========
Copyright (c) 2005 Bob Ippolito. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Academic Free License v. 2.1
============================
Copyright (c) 2005 Bob Ippolito. All rights reserved.
This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following notice immediately following the copyright notice for the Original Work:
Licensed under the Academic Free License version 2.1
1) Grant of Copyright License. Licensor hereby grants You a world-wide, royalty-free, non-exclusive, perpetual, sublicenseable license to do the following:
a) to reproduce the Original Work in copies;
b) to prepare derivative works ("Derivative Works") based upon the Original Work;
c) to distribute copies of the Original Work and Derivative Works to the public;
d) to perform the Original Work publicly; and
e) to display the Original Work publicly.
2) Grant of Patent License. Licensor hereby grants You a world-wide, royalty-free, non-exclusive, perpetual, sublicenseable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, to make, use, sell and offer for sale the Original Work and Derivative Works.
3) Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor hereby agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work, and by publishing the address of that information repository in a notice immediately following the copyright notice that applies to the Original Work.
4) Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior written permission of the Licensor. Nothing in this License shall be deemed to grant any rights to trademarks, copyrights, patents, trade secrets or any other intellectual property of Licensor except as expressly stated herein. No patent license is granted to make, use, sell or offer to sell embodiments of any patent claims other than the licensed claims defined in Section 2. No right is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under different terms from this License any Original Work that Licensor otherwise would have a right to license.
5) This section intentionally omitted.
6) Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work.
7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately proceeding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to Original Work is granted hereunder except under this disclaimer.
8) Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to any person for any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to liability for death or personal injury resulting from Licensor's negligence to the extent applicable law prohibits such limitation. Some jurisdictions do not allow the exclusion or limitation of incidental or consequential damages, so this exclusion and limitation may not apply to You.
9) Acceptance and Termination. If You distribute copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. Nothing else but this License (or another written agreement between Licensor and You) grants You permission to create Derivative Works based upon the Original Work or to exercise any of the rights granted in Section 1 herein, and any attempt to do so except under the terms of this License (or another written agreement between Licensor and You) is expressly prohibited by U.S. copyright law, the equivalent laws of other countries, and by international treaty. Therefore, by exercising any of the rights granted to You in Section 1 herein, You indicate Your acceptance of this License and all of its terms and conditions.
10) Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware.
11) Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of the U.S. Copyright Act, 17 U.S.C. § 101 et seq., the equivalent laws of other countries, and international treaty. This section shall survive the termination of this License.
12) Attorneys Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License.
13) Miscellaneous. This License represents the complete agreement concerning the subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable.
14) Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
15) Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You.
This license is Copyright (C) 2003-2004 Lawrence E. Rosen. All rights reserved. Permission is hereby granted to copy and distribute this license without modification. This license may not be modified without the express written permission of its copyright owner.
This diff is collapsed.
This diff is collapsed.
<?php
/**
* This program is part of Mahara
* This program is part of Pieforms
*
* 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
......@@ -16,30 +16,30 @@
* 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-element
* @package pieform
* @subpackage 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
* @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
/**
* Renders a button. Custom buttons are rendered nearly the same as
* normal submit buttons, only their name is changed (for use by the Form class
* internally).
* Renders an <input type="button"> element.
*
* The element must have the 'value' field set.
*
* @param array $element The element to render
* @param Form $form The form to render the element for
* @param Pieform $form The form to render the element for
* @return string The HTML for the element
*/
function form_render_button($element, $form) {
function pieform_render_button($element, Pieform $form) {
if (!isset($element['value'])) {
throw new PieformException('Button elements must have a value');
}
return '<input type="button"'
. Form::element_attributes($element)
. ' value="' . hsc($form->get_value($element)) . '">';
. Pieform::element_attributes($element)
. ' value="' . Pieform::hsc($element['value']) . '">';
}
?>
<?php
/**
* This program is part of Mahara
* This program is part of Pieforms
*
* 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
......@@ -16,40 +16,44 @@
* 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-element
* @package pieform
* @subpackage 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
* @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
/**
* 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).
* normal submit buttons, only their name is changed (for use by the Pieform
* 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
* @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 form_render_cancel($element, Form $form) {
$attributes = Form::element_attributes($element);
function pieform_render_cancel($element, Pieform $form) {
if (!isset($element['value'])) {
throw new PieformException('Cancel elements must have a value');
}
$attributes = Pieform::element_attributes($element);
$attributes = preg_replace('/name="(.*)"/', 'name="cancel_$1"', $attributes);
$attributes = preg_replace('/id="(.*)"/', 'id="cancel_$1"', $attributes);
return '<input type="submit"'
. $attributes
. ' value="' . hsc($form->get_value($element)) . '">';
. ' value="' . Pieform::hsc($element['value']) . '">';
}
// @todo how to support cancel buttons for ajax post? Possibly do a full post regardless...