Skip to content
Snippets Groups Projects
Commit 9e5f5e4b authored by Peter Rotich's avatar Peter Rotich
Browse files

Merge pull request #158 from greezybacon/issue/form-sanity

Fixup a few sanity issues on custom forms

Peter Rotich <peter@osticket.com>
parents c44a7ec0 12c84b88
No related branches found
No related tags found
No related merge requests found
......@@ -284,6 +284,9 @@ class DynamicFormField extends VerySimpleModel {
function isValid() {
if (count($this->errors()) || !parent::isValid())
return false;
if (!$this->get('label'))
$this->addError(
"Label is required for custom form fields", "label");
if ($this->get('required') && !$this->get('name'))
$this->addError(
"Variable name is required for required fields", "name");
......
......@@ -110,7 +110,10 @@ $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
<tr>
<td><i class="icon-sort"></i></td>
<td><input type="text" size="32" name="label-<?php echo $id; ?>"
value="<?php echo $f->get('label'); ?>"/></td>
value="<?php echo $f->get('label'); ?>"/>
<font class="error"><?php
if ($errors['label']) echo '<br/>'; echo $errors['label']; ?>
</td>
<td><select name="type-<?php echo $id; ?>" <?php
if (!$f->isChangeable()) echo 'disabled="disabled"'; ?>>
<?php foreach (FormField::allTypes() as $group=>$types) {
......
......@@ -83,9 +83,9 @@ INSERT INTO `%TABLE_PREFIX%form_entry_values` (
'-', ''),
'.', ''), 'X', A1.`phone_ext`))
FROM `%TABLE_PREFIX%ticket` A1
INNER JOIN `%TABLE_PREFIX%form` A4 ON (`type`='U')
INNER JOIN `%TABLE_PREFIX%form_entry` A2 ON (A2.`object_id`
= A1.`ticket_id` AND A2.`object_type` = 'U')
INNER JOIN `%TABLE_PREFIX%form` A4 ON (A4.`id` = A2.`form_id`)
INNER JOIN `%TABLE_PREFIX%form_field` A3 ON (A2.`form_id`
= A4.`id`)
WHERE A3.`name` = 'phone' AND LENGTH(A1.`phone`)
......
......@@ -17,6 +17,7 @@ if($_POST) {
$form->set($f, $_POST[$f]);
if ($form->isValid())
$form->save(true);
$names = array();
foreach ($form->getDynamicFields() as $field) {
$id = $field->get('id');
if ($_POST["delete-$id"] == 'on' && $field->isDeletable()) {
......@@ -38,6 +39,10 @@ if($_POST) {
$field->set($f, $_POST["$f-$id"]);
}
}
if (in_array($field->get('name'), $names))
$field->addError('Field variable name is not unique', 'name');
if ($field->get('name'))
$names[] = $field->get('name');
if ($field->isValid())
$field->save();
else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment