Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Duplication of userforms went wrong at 3.1.0-beta3


3 Posts   425 Views


Community Member, 81 Posts

13 May 2013 at 7:14pm

I'm trying to duplicate a page including form. Because 3.0.x doesn't have the ability to duplicate, I choosed to use the 3.1.0 beta

It works brilliant, except a part of the duplication in the form.

When set a CustomRule, and duplicate the page, the new page still get's the Rule from the old source. (e.g. "EditableRadioField13" instead of "EditableRadioField26"). Is there a easy solution without a complete rebuild of the function duplicate()?


Community Member, 81 Posts

17 May 2013 at 1:25am

Ok, i rewrote the function duplicate() in UserDefinedForm.php by myself. It duplicates correctly and takes over the right conditions.

public function duplicate($doWrite = true) {
      $page = parent::duplicate($doWrite);

      // the form fields
      if($this->Fields()) {
         foreach($this->Fields() as $field) {
            $newField = $field->duplicate();
            $newField->ParentID = $page->ID;
$newField->Name = $newField->ClassName.$newField->ID;

//trek eerst de CustomRules uit elkaar
$ar = array();
$ar = unserialize($field->CustomRules);

if(sizeof($ar) >0){
$ConditionField = $ar[0]['ConditionField'];
if($ConditionField != ""){
//$ar2 = preg_split("/(\d+)/", $ConditionField, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);

//selecteer sorteervolgorde, classname uit editableformfield waar naam = $ConditionField
$child = DataObject::get('EditableFormField')->where('Name = \''.$ConditionField.'\'')->first();
$sort = $child->Sort;
$classname = $child->ClassName;

//selecteer id, waar sorteervolgorde en nieuwe parent id
$new = DataObject::get('EditableFormField')->where('Sort = '.$sort.' AND ParentID = '.$newField->ParentID)->first();

$ar[0]['ConditionField'] = $new->Name;
$ar = serialize($ar);
$newField->CustomRules = $ar;

$newField->doPublish('Stage', 'Live', true);
$page->doPublish('Stage', 'Live');

// the emails
      if($this->EmailRecipients()) {
         foreach($this->EmailRecipients() as $email) {
            $newEmail = $email->duplicate();
            $newEmail->FormID = $page->ID;

      return $page;


Community Member, 1 Post

4 June 2013 at 9:54pm

See also GitHub issue #19: [url][/url]

I've also tried to fix this and done a pull request: [url][/url]