Copy form in V4

JerseyGirl 02 Mar, 2011
I want to make a copy of my form, so I can revert to it if need be after making significant changes.

I used the Copy Form icon in V4. It made another form which contained all of the elements of the first form, but none of the actions.

Did I do something wrong or is this a bug?

Thanks!
GreyHead 03 Mar, 2011
Hi JerseyGirl,

As you say the Form Copy doesn't seem to copy the actions. Here's a fixed version of the copy_form() function from admin.chronoforms.php (around line 168)
function copy_form(){
	global $mainframe;
	$database =& JFactory::getDBO();
	$row =& JTable::getInstance('chronoforms', 'Table'); 
	if(isset($_POST['cb']) && !empty($_POST['cb'])){		
		$row->load($_POST['cb'][0]);
		$row->id = '';
		$row->name = 'copy_of_'.$row->name;
		if(!$row->store()){
			JError::raiseWarning(100, $row->getError());
			$mainframe->redirect("index2.php?option=com_chronoforms");
		}
		$new_id = $row->id;
		unset($row);
		$query = "
			SELECT `id`
				FROM `#__chronoform_actions`
				WHERE `chronoform_id` = {$_POST['cb'][0]};
		";
		$database->setQuery($query);
		$row_ids = $database->loadResultArray(); 
		foreach ( $row_ids as $id ) {
			$row =& JTable::getInstance('chronoformActions', 'Table');
			$row->load($id);
			$row->id = '';
			$row->chronoform_id = $new_id;
			if(!$row->store()){
				JError::raiseWarning(100, $row->getError());
				$mainframe->redirect("index2.php?option=com_chronoforms");
			}
		}
	}
	$mainframe->redirect("index2.php?option=com_chronoforms", "Form successfully copied.");
}
The new code in the second half of the function gets a list of the actions and copies those as well.

So far seems to work OK but please take care and backup before using.

Bob
This topic is locked and no more replies can be posted.