Commit 8a875634 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Pieform element for an array of text fields (bug #997834)

Sometimes we may want a user to enter multiple text fields, without
specifying how many.  This will be useful for collecting multiple
mobile upload tokens for users with more than one device.

Change-Id: I1862a223f1ea601a2e28009527c170e1aa3115c8
Signed-off-by: default avatarRichard Mansfield <>
parent d0204b9f
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2012 Catalyst IT Ltd and others; see:
* 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 3 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
* 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, see <>.
* @package mahara
* @subpackage form-element
* @author Richard Mansfield
defined('INTERNAL') || die();
* Multiple text elements
* @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_element_multitext(Pieform $form, $element) {
$smarty = smarty_core();
$smarty->left_delimiter = '{{';
$smarty->right_delimiter = '}}';
$values = array();
foreach ($form->get_value($element) as $v) {
if ($v) {
$values[] = hsc($v);
$smarty->assign('value', $values);
$smarty->assign('next', count($values));
$smarty->assign('name', $form->get_name() . '_' . $element['name']);
return $smarty->fetch('form/multitext.tpl');
function pieform_element_multitext_get_value(Pieform $form, $element) {
if (isset($element['value'])) {
return $element['value'];
$global = $form->get_property('method') == 'get' ? $_GET : $_POST;
$name = $form->get_name() . '_' . $element['name'];
if ($form->is_submitted() && isset($global[$name]) && is_array($global[$name])) {
return array_values($global[$name]);
if (isset($element['defaultvalue'])) {
return $element['defaultvalue'];
return null;
......@@ -191,6 +191,7 @@ th {
.wysiwyg th,
.filebrowser th,
.textarea th,
.multitext th,
#edit_interaction_weight_container th,
.userlist th {
vertical-align: top;
<script type="text/javascript">
var {{$name}}_current = {{$next}};
var {{$name}}_newrefinput;
var {{$name}}_newref;
function {{$name}}_new() {
{{$name}}_newrefinput = INPUT({'type': 'text', 'name': '{{$name}}[' + {{$name}}_current + ']'});
var {{$name}}_newref = DIV(null, {{$name}}_newrefinput);
appendChildNodes('{{$name}}_list', {{$name}}_newref);
<div id="{{$name}}_list">
{{foreach from=$value key=k item=v}}
<input type="text" name="{{$name}}[{{$k}}]" value="{{$v}}">
<a href="" onclick="removeElement(this.parentNode); return false;">[x]</a>
<input type="text" name="{{$name}}[{{$next}}]" value="">
<a href="" onclick="{{$name}}_new(); return false;">[+]</a>
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