/** * Renders form elements inside a <table>. * * @param Pieform $form The form the element is being rendered for * @param array $element The element to be rendered * @return string The element rendered inside an appropriate container */ function pieform_renderer_table(Pieform $form, $element) { /*{{{*/ $formname = $form->get_name(); if ($element['type'] == 'fieldset') { // Add table tags to the build element, to preserve HTML compliance $builtelement = $element['html']; if (0 === strpos($builtelement, "\n<fieldset")) { $closelegendpos = strpos($builtelement, '</legend>'); if ($closelegendpos !== false) { $closelegendpos += 9; $builtelement = substr($builtelement, 0, $closelegendpos) . '<table><tbody>' . substr($builtelement, $closelegendpos); } else { $pos = strpos($builtelement, '>') + 1; $builtelement = substr($builtelement, 0, $pos) . '<table><tbody>' . substr($builtelement, $pos); } } else { $builtelement = substr($builtelement, 0, 11) . '<table><tbody>' . substr($builtelement, 11); } $builtelement = substr($builtelement, 0, -12) . '</tbody></table></fieldset>'; $result = "\t<tr>\n\t\t<td colspan=\"2\">"; $result .= $builtelement; $result .= "</td>\n\t</tr>"; return $result; } $result = "\t<tr"; $result .= ' id="' . $formname . '_' . $element['name'] . '_container"'; // Set the class of the enclosing <tr> to match that of the element if (!empty($element['class'])) { $result .= ' class="' . $element['class'] . '"'; } $result .= ">\n\t\t"; $result .= '<th>'; if (isset($element['labelhtml'])) { $result .= $element['labelhtml']; } $result .= "</th>\n\t\t<td>"; $result .= $element['html']; if (isset($element['helphtml'])) { $result .= ' ' . $element['helphtml']; } $result .= "</td>\n\t</tr>\n"; // Description - optional description of the element, or other note that should be visible // on the form itself (without the user having to hover over contextual help if ((!$form->has_errors() || $form->get_property('showdescriptiononerror')) && !empty($element['description'])) { if ($form->get_property('descriptionintwocells')) { $result .= "\t<tr>\n\t\t<td></td><td class=\"description\">"; } else { $result .= "\t<tr>\n\t\t<td colspan=\"2\" class=\"description\">"; } $result .= $element['description']; $result .= "</td>\n\t</tr>\n"; } if (!empty($element['error'])) { $result .= "\t<tr>\n\t\t<td colspan=\"2\" class=\"errmsg\">"; $result .= $element['error']; $result .= "</td>\n\t</tr>\n"; } return $result; }
/** * Renders form elements all on one line. * * @param Pieform $form The form the element is being rendered for * @param array $element The element that is being rendered * @return string The element rendered inside an appropriate container */ function pieform_renderer_oneline(Pieform $form, $element) { /*{{{*/ $formname = $form->get_name(); // Set the class of the enclosing <div> to match that of the element $result = '<span'; if (isset($element['name'])) { $result .= ' id="' . $formname . '_' . $element['name'] . '_container"'; } if (!empty($element['class'])) { $result .= ' class="' . $element['class'] . '"'; } $result .= '>'; if (isset($element['title']) && $element['title'] !== '' && $element['type'] != 'fieldset') { if (!empty($element['nolabel'])) { // Don't bother with a label for the element $result .= Pieform::hsc($element['title']); } else { $result .= '<label for="' . $element['id'] . '">' . Pieform::hsc($element['title']) . '</label>'; } if ($form->get_property('requiredmarker') && !empty($element['rules']['required'])) { $result .= ' <span class="requiredmarker">*</span>'; } } $result .= $element['html']; $result .= "</span>"; return $result; }
function pieform_element_weight_get_value(Pieform $form, $element) { pieform_element_weight_validate_element($element); $name = $element['name']; $global = $form->get_property('method') == 'get' ? $_GET : $_POST; $value = null; if (isset($element['value'])) { $value = $element['value']; } else { if (isset($global[$name])) { $value = $global[$name]; } else { if (isset($element['defaultvalue'])) { $value = $element['defaultvalue']; } } } // How should we return the value? In theory, there could be several ways // in which the caller wants the data to be returned. For now, only one // "policy" is implemented switch ($element['returnpolicy']) { case 'renumber-from-zero': return pieform_element_weight_returnpolicy_renumber_from_zero($element, $value); } return null; }
/** * Returns the color value of the color selector element from the request or transparent * * @param Pieform $form The form the element is attached to * @param array $element The element to get the value for * @return string A 6-digit hex color value, or the string "transparent" */ function pieform_element_color_get_value(Pieform $form, $element) { $name = $element['name']; $global = $form->get_property('method') == 'get' ? $_GET : $_POST; if ($form->is_submitted() && isset($global[$name . '_color']) && !isset($global[$name . '_optional'])) { $color = $global[$name . '_color']; // Whitelist for a 6-digit hex color $color = preg_replace('/[^a-f0-9]/i', '', $color); if (strlen($color) >= 6) { $color = substr($color, 0, 6); } else { if (strlen($color) >= 3) { // If they provided a 3-digit color string, convert it into a 6-digit one by doubling each digit $color = substr($color, 0, 3); $color = $color[0] . $color[0] . $color[1] . $color[1] . $color[2] . $color[2]; } else { $color = ''; } } if ($color === '') { return 'transparent'; } $color = "#{$color}"; return $color; } return 'transparent'; }
function pieform_element_captcha_get_value(Pieform $form, $element) { global $SESSION; $name = $element['name']; $global = $form->get_property('method') == 'get' ? $_GET : $_POST; return isset($global[$name]) && strtolower($global[$name]) == strtolower($SESSION->get($form->get_name() . '_' . $name)); }
/** * Renders form elements inside <div>s. * * @param Pieform $form The form the element is being rendered for * @param array $element The element to be rendered * @return string The element rendered inside an appropriate container */ function pieform_renderer_div(Pieform $form, $element) { /*{{{*/ $formname = $form->get_name(); // Set the class of the enclosing <div> to match that of the element $result = '<div'; if (isset($element['name'])) { $result .= ' id="' . $formname . '_' . $element['name'] . '_container"'; } if (!empty($element['class'])) { $result .= ' class="' . $element['class'] . '"'; } $result .= '>'; if (isset($element['labelhtml'])) { $result .= $element['labelhtml']; } //$result .= $builtelement; $result .= $element['html']; if (isset($element['helphtml'])) { $result .= ' ' . $element['helphtml']; } // Description - optional description of the element, or other note that should be visible // on the form itself (without the user having to hover over contextual help if ((!$form->has_errors() || $form->get_property('showdescriptiononerror')) && !empty($element['description'])) { $result .= '<div class="description"> ' . Pieform::hsc($element['description']) . "</div>"; } if (!empty($element['error'])) { $result .= '<div class="errmsg">' . Pieform::hsc($element['error']) . '</div>'; } $result .= "</div>\n"; return $result; }
function pieform_element_artefactchooser_get_value(Pieform $form, $element) { $name = $element['name']; $global = $form->get_property('method') == 'get' ? $_GET : $_POST; if (isset($global[$name]) || isset($global["{$name}_onpage"])) { $value = isset($global[$name]) ? $global[$name] : array(); if ($element['selectone']) { if (!$value) { return null; } if (preg_match('/^\\d+$/', $value)) { return intval($value); } } else { $onpage = isset($global["{$name}_onpage"]) ? $global["{$name}_onpage"] : array(); $selected = is_array($value) ? array_map('intval', array_keys($value)) : array(); $default = is_array($element['defaultvalue']) ? $element['defaultvalue'] : array(); // 1) Start with what's currently available // 2) Remove everything on the page that was active when submitted // 3) Add in everything that was selected $value = array_merge(array_diff($default, $onpage), $selected); return array_map('intval', $value); } throw new PieformException("Invalid value for artefactchooser form element '{$name}' = '{$value}'"); } if (isset($element['defaultvalue'])) { return $element['defaultvalue']; } return null; }
/** * Renders a hidden 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_element_hidden(Pieform $form, $element) { /*{{{*/ if (!array_key_exists('value', $element)) { throw new PieformException('The hidden element "' . $element['name'] . '" must have a value set'); } if (!empty($element['sesskey']) && $form->get_property('method') != 'post') { throw new PieformException('Sesskey values should be POSTed'); } $value = $form->get_value($element); if (is_array($value)) { $result = ''; foreach ($value as $k => $v) { if (is_array($v)) { foreach ($v as $subk => $subv) { $result .= '<input type="hidden" name="' . Pieform::hsc($element['name']) . '[' . Pieform::hsc($k) . '][' . Pieform::hsc($subk) . ']" value="' . Pieform::hsc($subv) . "\">\n"; } } else { $result .= '<input type="hidden" name="' . Pieform::hsc($element['name']) . '[' . Pieform::hsc($k) . ']" value="' . Pieform::hsc($v) . "\">\n"; } } return $result; } return '<input type="hidden"' . $form->element_attributes($element, array('accesskey', 'onclick', 'size', 'style', 'tabindex')) . ' value="' . Pieform::hsc($form->get_value($element)) . "\">\n"; }
/** * 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 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_element_fieldset(Pieform $form, $element) { /*{{{*/ global $_PIEFORM_FIELDSETS; $result = "\n<fieldset"; if (!empty($element['collapsible']) || !empty($element['class'])) { if (!isset($element['legend']) || $element['legend'] === '') { Pieform::info('Collapsible fieldsets should have a legend so they can be toggled'); } $classes = array('collapsible'); $formname = $form->get_name(); if (!isset($_PIEFORM_FIELDSETS['forms'][$formname])) { $_PIEFORM_FIELDSETS['forms'][$formname] = array('formname' => $formname); } // Work out whether any of the children have errors on them $error = false; foreach ($element['elements'] as $subelement) { if (isset($subelement['error'])) { $error = true; break; } } if (!empty($element['collapsed']) && !$error) { $classes[] = 'collapsed'; } if (!empty($element['class'])) { $classes[] = Pieform::hsc($element['class']); } $result .= ' class="' . implode(' ', $classes) . '"'; } $result .= ">\n"; if (isset($element['legend'])) { $result .= '<legend>'; if (!empty($element['collapsible'])) { $result .= '<a href="">' . Pieform::hsc($element['legend']) . '</a>'; } else { $result .= Pieform::hsc($element['legend']); } // Help icon if (!empty($element['help'])) { $function = $form->get_property('helpcallback'); if (function_exists($function)) { $result .= $function($form, $element); } else { $result .= '<span class="help"><a href="" title="' . Pieform::hsc($element['help']) . '" onclick="return false;">?</a></span>'; } } $result .= "</legend>\n"; } foreach ($element['elements'] as $subname => $subelement) { if ($subelement['type'] == 'hidden') { throw new PieformError("You cannot put hidden elements in fieldsets"); } $result .= "\t" . pieform_render_element($form, $subelement); } $result .= "</fieldset>\n"; return $result; }
function pieform_element_tags_get_value(Pieform $form, $element) { $name = $element['name']; $global = $form->get_property('method') == 'get' ? $_GET : $_POST; if (!isset($global[$name])) { return null; } $value = preg_split("/\\s*,\\s*/", trim($global[$name])); $value = array_unique(array_filter($value, create_function('$v', 'return !empty($v);'))); return $value; }
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 ($form->is_submitted() && isset($global[$element['name'] . '_x'])) { return true; } return null; }
/** * 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 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_element_fieldset(Pieform $form, $element) { /*{{{*/ $result = "\n<fieldset"; if (!empty($element['collapsible']) || !empty($element['class'])) { if (!isset($element['legend']) || $element['legend'] === '') { Pieform::info('Collapsible fieldsets should have a legend so they can be toggled'); } $classes = array('collapsible'); // Work out whether any of the children have errors on them $error = false; foreach ($element['elements'] as $subelement) { if (isset($subelement['error'])) { $error = true; break; } } if (!empty($element['collapsed']) && !$error) { $classes[] = 'collapsed'; } if (!empty($element['class'])) { $classes[] = $element['class']; } $result .= ' class="' . implode(' ', $classes) . '"'; } $result .= ">\n"; if (isset($element['legend'])) { $result .= '<legend'; if (!empty($element['collapsible'])) { $id = substr(md5(microtime()), 0, 4); $result .= ' id="' . $id . '">'; $result .= '<script type="text/javascript">'; $result .= "var a = A({'href':'', 'tabindex':{$form->get_property('tabindex')}}, " . json_encode($element['legend']) . "); "; $result .= "connect(a, 'onclick', function(e) { toggleElementClass('collapsed', \$('{$id}').parentNode); e.stop(); });"; $result .= "replaceChildNodes('{$id}', a);</script>"; } else { $result .= '>' . Pieform::hsc($element['legend']); } $result .= "</legend>\n"; } foreach ($element['elements'] as $subname => $subelement) { if ($subelement['type'] == 'hidden') { throw new PieformError("You cannot put hidden elements in fieldsets"); } $result .= "\t" . pieform_render_element($form, $subelement); } $result .= "</fieldset>\n"; return $result; }
function pieform_element_password_get_value(Pieform $form, $element) { /*{{{*/ if (isset($element['value'])) { return $element['value']; } $global = $form->get_property('method') == 'get' ? $_GET : $_POST; if ($form->is_submitted() && isset($global[$element['name']])) { return $global[$element['name']]; } if (isset($element['defaultvalue'])) { return $element['defaultvalue']; } return null; }
function pieform_element_textarea_get_value(Pieform $form, $element) { /*{{{*/ if (isset($element['value'])) { return $element['value']; } $global = $form->get_property('method') == 'get' ? $_GET : $_POST; if ($form->is_submitted() && isset($global[$element['name']])) { return str_replace("\r\n", "\n", $global[$element['name']]); } if (isset($element['defaultvalue'])) { return $element['defaultvalue']; } return ''; }
function pieform_element_emaillist_get_value(Pieform $form, $element) { $name = $element['name']; $global = $form->get_property('method') == 'get' ? $_GET : $_POST; if (!isset($global[$name . '_valid']) || !is_array($global[$name . '_valid'])) { return null; } $value = array(); $value['default'] = $global[$name . '_selected']; $value['validated'] = $global[$name . '_valid']; if (isset($global[$name . '_invalid']) && is_array($global[$name . '_invalid'])) { $value['unvalidated'] = $global[$name . '_invalid']; } return $value; }
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; }
function pieform_element_userlist_get_value(Pieform $form, $element) { $name = $element['name']; $global = $form->get_property('method') == 'get' ? $_GET : $_POST; if (isset($global[$name])) { $value = $global[$name]; if ($value == '') { return array(); } if (preg_match('/^(\\d+(,\\d+)*)$/', $value)) { return array_map('intval', explode(',', $value)); } throw new PieformException("Invalid value for userlist form element '{$name}' = '{$value}'"); } return null; }
/** * Return the value of the element. This returns an array with the defaultvalue (if supplied), * and the value newly submitted in this form (if supplied) * * @param Pieform $form * @param array $element * @return array with two keys, 'defaultvalue' and 'submittedvalue' */ function pieform_element_passwordnoread_get_value(Pieform $form, $element) { $ret = array(); if (isset($element['defaultvalue'])) { $ret['defaultvalue'] = $element['defaultvalue']; } else { $ret['defaultvalue'] = null; } $global = $form->get_property('method') == 'get' ? $_GET : $_POST; if ($form->is_submitted() && isset($global[$element['name']])) { $ret['submittedvalue'] = $global[$element['name']]; } else { $ret['submittedvalue'] = null; } return $ret; }
function pieform_element_trafficlights_get_value(Pieform $form, $element) { /*{{{*/ $global = $form->get_property('method') == 'get' ? $_GET : $_POST; if (isset($element['value'])) { $value = $element['value']; } else { if ($form->is_submitted() && isset($global[$element['name']])) { $value = $global[$element['name']]; } else { if (!$form->is_submitted() && isset($element['defaultvalue'])) { $value = $element['defaultvalue']; } else { $value = null; } } } return $value; }
function pieform_element_checkbox_get_value(Pieform $form, $element) { /*{{{*/ $name = $element['name']; $global = $form->get_property('method') == 'get' ? $_GET : $_POST; if (isset($element['value'])) { return $element['value']; } if ($form->is_submitted()) { if (isset($global[$name])) { return true; } return false; } if (isset($element['defaultvalue'])) { return $element['defaultvalue']; } return false; }
function pieform_element_checkboxes_get_value(Pieform $form, $element) { /*{{{*/ $global = $form->get_property('method') == 'get' ? $_GET : $_POST; if (isset($element['value'])) { $values = (array) $element['value']; } else { if ($form->is_submitted() && isset($global[$element['name']])) { $values = (array) $global[$element['name']]; } else { if (!$form->is_submitted() && isset($element['defaultvalue'])) { $values = (array) $element['defaultvalue']; } else { $values = array(); } } } return $values; }
function pieform_element_authlist_get_value(Pieform $form, $element) { $name = $element['name']; $global = $form->get_property('method') == 'get' ? $_GET : $_POST; $value = array(); if (array_key_exists('instancePriority', $global) && !empty($global['instancePriority'])) { $value['instancearray'] = explode(',', $global['instancePriority']); } else { $value['instancearray'] = $element['instancearray']; } if (array_key_exists('deleteList', $global) && !empty($global['deleteList'])) { $value['deletearray'] = explode(',', $global['deleteList']); } else { $value['deletearray'] = array(); } $value['instancelist'] = $element['options']; $value['authtypes'] = $element['authtypes']; $value['instancePriority'] = $element['instancestring']; $value['institution'] = $element['institution']; return $value; }
function pieform_element_rolepermissions_get_value(Pieform $form, $element) { /*{{{*/ if (isset($element['value'])) { return $element['value']; } if (isset($element['defaultvalue'])) { $value = $element['defaultvalue']; } else { $value = group_get_default_artefact_permissions($element['group']); } if ($form->is_submitted()) { $global = $form->get_property('method') == 'get' ? $_GET : $_POST; $prefix = $form->get_name() . '_' . $element['name'] . '_p'; foreach ($value as $r => $perms) { foreach (array_keys(get_object_vars($perms)) as $p) { if ($r != 'admin') { $value[$r]->{$p} = param_boolean($prefix . '_' . $r . '_' . $p); } } } } return $value; }
function pieform_element_filebrowser_changefolder(Pieform $form, $element, $folder) { $owner = $ownerid = $group = $institution = $user = null; $prefix = $form->get_name() . '_' . $element['name']; if (isset($element['tabs'])) { if ($owner = param_variable($prefix . '_owner', null)) { if ($owner == 'site') { $owner = 'institution'; $institution = $ownerid = 'mahara'; } else { if ($ownerid = param_variable($prefix . '_ownerid', null)) { if ($owner == 'group') { $group = (int) $ownerid; } else { if ($owner == 'institution') { $institution = $ownerid; } else { if ($owner == 'user') { $user = true; } } } } } } } // If changing to a group folder, check whether the user can edit it if ($g = $owner ? $group : $form->get_property('group')) { if (!pieform_element_filebrowser_view_group_folder($g, $folder)) { return array('error' => true, 'message' => get_string('cannotviewfolder', 'artefact.file')); } $editgroupfolder = pieform_element_filebrowser_edit_group_folder($g, $folder); } return array('error' => false, 'changedfolder' => true, 'folder' => $folder, 'disableedit' => isset($editgroupfolder) && $editgroupfolder == false, 'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $folder, null, $user, $group, $institution), 'newpath' => pieform_element_filebrowser_build_path($form, $element, $folder, $owner, $ownerid)); }
/** * 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_bytes_get_value(Pieform $form, $element) { /*{{{*/ $name = $element['name']; $global = $form->get_property('method') == 'get' ? $_GET : $_POST; $unit = $global[$name . '_units']; $allunits = pieform_element_bytes_get_bytes_units(); $number = $global[$name]; if (!is_numeric($number)) { $form->set_error($name, $form->i18n('element', 'bytes', 'invalidvalue', $element)); } if (!in_array($unit, $allunits) || $number < 0) { return null; } return $number * pieform_element_bytes_in($unit); }
function add_annotation_feedback_form_validate(Pieform $form, $values) { require_once get_config('libroot') . 'antispam.php'; if ($form->get_property('spam')) { $spamtrap = new_spam_trap(array(array('type' => 'body', 'value' => $values['message']))); if ($form->spam_error() || $spamtrap->is_spam()) { $msg = get_string('formerror'); $emailcontact = get_config('emailcontact'); if (!empty($emailcontact)) { $msg .= ' ' . get_string('formerroremail', 'mahara', $emailcontact, $emailcontact); } $form->set_error('message', $msg); } } // Make sure that the user has not manipulated the ids. if (empty($values['artefactid']) && empty($values['viewid'])) { // One of them must have data. $form->set_error('message', get_string('invalidannotationfeedbacklinkerror', 'artefact.annotation')); } if (empty($values['annotationid'])) { $form->set_error('message', get_string('annotationinformationerror', 'artefact.annotation')); } if (!empty($values['viewid']) && !can_view_view($values['viewid'])) { // The user does not access to this view. $form->set_error('message', get_string('noaccesstoview', 'view')); } if (!empty($values['viewid']) && !artefact_in_view($values['annotationid'], $values['viewid'])) { // The annotation is not on the view. $form->set_error('message', get_string('accessdenied', 'error')); } if (!empty($values['artefactid']) && !empty($values['viewid']) && !artefact_in_view($values['artefactid'], $values['viewid'])) { // The artefact is not on the view. $form->set_error('message', get_string('accessdenied', 'error')); } if (empty($values['message'])) { $form->set_error('message', get_string('annotationfeedbackempty', 'artefact.annotation')); } $result = probation_validate_content($values['message']); if ($result !== true) { $form->set_error('message', get_string('newuserscantpostlinksorimages')); } }
function pieform_get_help(Pieform $form, $element) { return get_help_icon($form->get_property('plugintype'), $form->get_property('pluginname'), $form->get_name(), $element['name']); }
function add_feedback_form_validate(Pieform $form, $values) { require_once get_config('libroot') . 'antispam.php'; if ($form->get_property('spam')) { $spamtrap = new_spam_trap(array(array('type' => 'body', 'value' => $values['message']))); if ($form->spam_error() || $spamtrap->is_spam()) { $msg = get_string('formerror'); $emailcontact = get_config('emailcontact'); if (!empty($emailcontact)) { $msg .= ' ' . get_string('formerroremail', 'mahara', $emailcontact, $emailcontact); } $form->set_error('message', $msg); } } if (empty($values['attachments']) && empty($values['message'])) { $form->set_error('message', get_string('messageempty', 'artefact.comment')); } $result = probation_validate_content($values['message']); if ($result !== true) { $form->set_error('message', get_string('newuserscantpostlinksorimages')); } }
function pieform_get_help(Pieform $form, $element) { $plugintype = isset($element['helpplugintype']) ? $element['helpplugintype'] : $form->get_property('plugintype'); $pluginname = isset($element['helppluginname']) ? $element['helppluginname'] : $form->get_property('pluginname'); $formname = isset($element['helpformname']) ? $element['helpformname'] : $form->get_name(); return get_help_icon($plugintype, $pluginname, $formname, $element['name'], '', '', isset($element['title']) ? $element['title'] : null); }
/** * Renders form elements inside <div>s. * * @param Pieform $form The form the element is being rendered for * @param array $element The element to be rendered * @return string The element rendered inside an appropriate container */ function pieform_renderer_div(Pieform $form, $element) { /*{{{*/ $formname = $form->get_name(); // Set the class of the enclosing <div> to match that of the element $prefix = ''; $suffix = ''; $inner = ''; // allow forms to be rendered without a wrapping div if (!isset($element['renderelementsonly'])) { $prefix = '<div'; if (isset($element['name'])) { $prefix .= ' id="' . $formname . '_' . Pieform::hsc($element['name']) . '_container"'; } // all elements should be form groups by default except button if (!isset($element['isformgroup'])) { $element['isformgroup'] = true; } if (isset($element['type'])) { $element['isformgroup'] = $element['type'] === 'button' ? false : $element['isformgroup']; } // add form-group classes to all real form fields $formgroupclass = $element['isformgroup'] ? 'form-group' : ''; if (isset($element['class'])) { // remove form-control class and btn class (these should be on the element only) $element['class'] = str_replace("btn-", " ", $element['class']); $element['class'] = str_replace("form-control ", "", $element['class']); $element['class'] = $element['class'] . ' ' . $formgroupclass; } else { $element['class'] = $formgroupclass; } if (isset($element['collapsible'])) { $element['class'] = $element['class'] . ' collapsible-group'; } // add bootstrap has-error class to any error fields if (strpos($element['class'], 'error') !== false) { $element['class'] = $element['class'] . ' has-error'; } $prefix .= ' class="' . Pieform::hsc($element['class']) . '"'; $prefix .= '>'; } if (isset($element['labelhtml'])) { $inner .= $element['labelhtml']; } if (isset($element['prehtml'])) { $inner .= '<span class="prehtml">' . $element['prehtml'] . '</span>'; } if (isset($element['html'])) { $inner .= $element['html']; } if (isset($element['posthtml'])) { $inner .= '<span class="posthtml">' . $element['posthtml'] . '</span>'; } if (isset($element['helphtml'])) { $inner .= ' ' . $element['helphtml']; } // Description - optional description of the element, or other note that should be visible // on the form itself (without the user having to hover over contextual help if ((!$form->has_errors() || $form->get_property('showdescriptiononerror')) && !empty($element['descriptionhtml'])) { $inner .= '<div class="description"> ' . $element['descriptionhtml'] . "</div>"; } if (!empty($element['error'])) { $inner .= '<div class="errmsg">' . $element['errorhtml'] . '</div>'; } if (!isset($element['renderelementsonly'])) { $suffix .= "</div>\n"; } $result = $prefix . $inner . $suffix; return $result; }