Skip to content

Commit

Permalink
Closes #922. Removing index in form_field table for those upgrading. …
Browse files Browse the repository at this point in the history
…Causes havoc for those who already had duplicate form field names/ form titles. However, we're now enforcing the following rules during form/field creation and for fresh installs : Forms must have unique titles, and custom fields within the same form must have unique names
  • Loading branch information
aoduor committed Nov 5, 2012
1 parent 7633164 commit aeef466
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
10 changes: 10 additions & 0 deletions application/controllers/admin/manage/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ public function index()
// Add some rules, the input field, followed by a list of checks, carried out in order
$post->add_rules('form_title','required', 'length[1,1000]');
$post->add_rules('form_description','required');

// Ensure that you don't have forms with duplicate names
$same_form = ORM::factory('form')
->where('form_title', $_POST['form_title'])
->count_all();

if ($same_form > 0)
{
$post->add_error('form_title', 'exists');
}
}
elseif ($post->action == 'd')
{
Expand Down
1 change: 1 addition & 0 deletions application/models/form_field.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function validate(array & $array, $save = FALSE)
{
$field_name = ORM::factory('form_field')
->where('field_name', $array->field_name)
->where('form_id', $array->form_id)
->count_all();
if ($field_name > 0)
{
Expand Down
5 changes: 0 additions & 5 deletions sql/upgrade98-99.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
-- Add unique constraint on custom form field name/title
ALTER TABLE `form_field` ADD UNIQUE (
`field_name`
);

-- UPDATE db_version
UPDATE `settings` SET `value` = 99 WHERE `key` = 'db_version';
5 changes: 3 additions & 2 deletions sql/ushahidi.sql
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,8 @@ CREATE TABLE IF NOT EXISTS `form` (
`form_title` varchar(200) NOT NULL,
`form_description` text,
`form_active` tinyint(4) DEFAULT '1',
PRIMARY KEY (`id`)
PRIMARY KEY (`id`),
UNIQUE KEY `form_title` (`form_title`),
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Stores all report submission forms created(default+custom)' AUTO_INCREMENT=2 ;

--
Expand Down Expand Up @@ -686,7 +687,7 @@ CREATE TABLE IF NOT EXISTS `form_field` (
`field_ispublic_visible` tinyint(4) NOT NULL DEFAULT '0',
`field_ispublic_submit` tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `field_name` (`field_name`),
UNIQUE KEY `field_name` ( `field_name` , `form_id` ),
KEY `fk_form_id` (`form_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Stores all custom form fields created by users' AUTO_INCREMENT=1 ;

Expand Down

0 comments on commit aeef466

Please sign in to comment.