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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

EditableFormFields with PageID == 0


Go to End


1858 Views

Avatar
xmedeko

Community Member, 94 Posts

11 June 2007 at 2:01pm

Hi,

if you create a new UserDefinedForm (a contact form), add a few fields and save it, then there are EditableFormFields with PageID == 0. When you create a second new contact page, you see these fields in the new contact page. To fix this, I propose the following patch:

--- FieldEditor.orig2 2007-06-11 13:50:30.000000000 +1200
+++ FieldEditor.php 2007-06-11 13:54:01.000000000 +1200
@@ -70,13 +70,15 @@
$newEditableData = $_REQUEST[$name][$newEditableID];

// if( is_numeric( $newEditableID ) )
- $editable = DataObject::get_one( 'EditableFormField', "`ParentID`='{$record->ID}' AND `EditableFormField`.`ID`='$newEditableID'" );
+ //`ParentID`=0 is for the new page
+ $editable = DataObject::get_one( 'EditableFormField', "(`ParentID`='{$record->ID}' OR `ParentID`=0) AND `EditableFormField`.`ID`='$newEditableID'" );

// check if we are updating an existing field
if( $editable && $missingFields[$editable->ID] )
unset( $missingFields[$editable->ID] );

// create a new object
+ // this should be now obsolete
if( !$editable && !empty( $newEditableData['Type'] ) && class_exists( $newEditableData['Type'] ) ) {
$editable = new $newEditableData['Type']();
$editable->ID = 0;
@@ -87,6 +89,9 @@
}

if( $editable ) {
+ if($editable->ParentID == 0) {
+ $editable->ParentID = $record->ID;
+ }
$editable->populateFromPostData($newEditableData);
//$editable->write();
}

This patch does not solve the situation, when the user discards changes in the new contact form, though :-( The new fields should be created just by javascript in the browser. They should be created in the database when saving the draft.