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

ComplexTableField Popup problem


Go to End


6 Posts   3636 Views

Avatar
fordy

Community Member, 46 Posts

21 April 2008 at 7:02am

I have finally got my head around creating new sections in the cms using complextablefield's but i am running into a few probs. I am getting the following error when opening the popup field on some instances.

FATAL ERROR: Form::callfieldmethod() Field 'MembersList' not found
At line 590 in /Applications/MAMP/htdocs/career/sapphire/forms/Form.php

I cant find why it is happening. Here is my code...

$section = $this->Section();
		
		if($section == 'employers') {
			$title = "<h2>Employers</h2>";
			$filter = "Group_Members.GroupID = 2";
			$sort = "Member.ID Desc";
		
		}else if ($section == 'candidates'){
			
			$title = "<h2>Candidates</h2>";
			$filter = "Group_Members.GroupID = 3";
			$sort = "Member.ID Desc";
		}
		
		$fieldList = array(
			'ID'=> 'ID',
			'FirstName' => 'First name',
			'Surname' => 'Surname',
			'Email' => 'Email',
			'Company' => 'Company',
			'City' => 'City',
			'Country' => 'Country',
			
		);
		
		$detailFields = new FieldSet();
	    $detailFields->push( new TextField( 'FirstName', 'Firstname' ) );
	    $detailFields->push( new TextField( 'Surname', 'Surname' ) );
	    $detailFields->push( new TextField( 'Email', 'Position' ) );
		$detailFields->push( new TextField( 'Company', 'Company' ) );
		$detailFields->push( new TextField( 'Address', 'Address Line 1' ) );
		$detailFields->push( new TextField( 'Address2', 'Address Line 2' ) );
		$detailFields->push( new TextField( 'City', 'City' ) );
		$detailFields->push( new TextField( 'ZipCode', 'Zip / Postal Code' ) );
		$detailFields->push( new TextField( 'Country', 'Country' ) );
		$detailFields->push( new TextField( 'HomePhone', 'Telephone' ) );
		$detailFields->push( new TextField( 'MobilePhone', 'Mobile Phone' ) );
		$detailFields->push( new TextField( 'NumVisit', 'Number of Visits' ) );
		$detailFields->push( new TextField( 'LastVisited', 'Last Visits' ) );  

		//$controller, $name, $sourceClass, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = ""
		
		$sourceJoin = "LEFT JOIN Group_Members ON Member.ID = Group_Members.MemberID";
		
		$tableList = new ComplexTableField($this,'MembersList', 'Member', $fieldList, $detailFields, $filter,$sort, $sourceJoin );
		
		$fields = new FieldSet(
			new HiddenField( 'ID' ),
			$tableList
		);
		
		//$actions = new FormAction( 'doForm', 'Save Me');
		
		return new Form($this, 'EditForm', $fields);

Can anyone help??

Avatar
Ingo

Forum Moderator, 801 Posts

21 April 2008 at 8:10pm

hm i don't see anything wrong with this code - are you doing some conditional switching for the fields you add to the form? a CTF popup needs the full context of the form its embedded into, so you have to make sure this context is available when being triggered through a URL (as opposed to opening the form directly). can you provide a Debug::backtrace() and the URL where this error occurs?

Avatar
fordy

Community Member, 46 Posts

22 April 2008 at 4:24am

Cheers Ingo,

The above code is in the EditForm() function.

$section = $this->Section(); executes:

public function Section() {
$url = rtrim($_SERVER['REQUEST_URI'], '/');
if(strrpos($url, '&')) {
$url = substr($url, 0, strrpos($url, '&'));
}
$section = substr($url, strrpos($url, '/') + 1);

if($section != 'employers' && $section != 'candidates' ) {
$section = 'employers';
}

return $section;
}

The backtrace is:

EmployerAdmin->EditForm()

call_user_func_array(Array,Array)
line 524 of ViewableData.php

ViewableData->cachedCall(EditForm,,)
line 565 of ViewableData.php

ViewableData->hasValue(EditForm)
line 7 of .cache.Applications.MAMP.htdocs.career.cms.templates.Includes.EmployerAdmin_right.ss

include(/Applications/MAMP/htdocs/career/silverstripe-cache/.cache.Applications.MAMP.htdocs.career.cms.templates.Includes.EmployerAdmin_right.ss)
line 190 of SSViewer.php

SSViewer->process(EmployerAdmin)
line 729 of ViewableData.php

ViewableData->renderWith(Array)
line 345 of LeftAndMain.php

LeftAndMain->Right()

call_user_func_array(Array,Array)
line 376 of ViewableData.php

ViewableData->XML_val(Right,,1)
line 96 of .cache.Applications.MAMP.htdocs.career.cms.templates.LeftAndMain.ss

include(/Applications/MAMP/htdocs/career/silverstripe-cache/.cache.Applications.MAMP.htdocs.career.cms.templates.LeftAndMain.ss)
line 190 of SSViewer.php

SSViewer->process(EmployerAdmin)
line 245 of Controller.php

Controller->defaultAction(index,Array)
line 216 of Controller.php

Controller->run(Array)
line 76 of Director.php

Director::direct(admin/careermembers/)
line 110 of main.php

Avatar
fordy

Community Member, 46 Posts

23 April 2008 at 10:12am

Still stumped on this one :-(

Anyone have any ideas?

Avatar
fordy

Community Member, 46 Posts

25 April 2008 at 4:23am

Got this one fixed. Not sure how but it's working.

I have run into a new problem though.

I am trying to show related data via a left join on the CTF. It is filtering with the join table but not showing. How can I do this?

Also, is there any way I can show related field data on the popup from a CTF?

Here is my latest code...

	public function EditForm() {
		
		$section = $this->Section();
		
		//$section = 'employers';
		
		if($section == 'employers') {
			$title = "<h2>Employers</h2>";
			$filter = "Group_Members.GroupID = 2";
			$sort = "Member.ID Desc";
		
		}else if ($section == 'candidates'){
			
			$title = "<h2>Candidates</h2>";
			$filter = "Group_Members.GroupID = 3";
			$sort = "Member.ID Desc";
		}
		
		$fieldList = array(
			
			'FirstName' => 'First name',
			'Surname' => 'Surname',
			'Email' => 'Email',
			'Company' => 'Company',
			'City' => 'City',
			'Country' => 'Country',
			'GroupID' => "Group"
			
		);
		
		$detailFields = new FieldSet();
		$detailFields->push( new TextField( 'ID', 'ID'));
	    $detailFields->push( new TextField( 'FirstName', 'Firstname' ) );
	    $detailFields->push( new TextField( 'Surname', 'Surname' ) );
	    $detailFields->push( new TextField( 'Email', 'Position' ) );
	    if($section == 'employers') {
	    	$detailFields->push( new TextField( 'Company', 'Company' ) );
	    }
		$detailFields->push( new TextField( 'Address', 'Address Line 1' ) );
		$detailFields->push( new TextField( 'Address2', 'Address Line 2' ) );
		$detailFields->push( new TextField( 'City', 'City' ) );
		$detailFields->push( new TextField( 'ZipCode', 'Zip / Postal Code' ) );
		$detailFields->push( new TextField( 'Country', 'Country' ) );
		$detailFields->push( new TextField( 'HomePhone', 'Telephone' ) );
		$detailFields->push( new TextField( 'MobilePhone', 'Mobile Phone' ) );
		$detailFields->push( new TextField( 'NumVisit', 'Number of Visits' ) );
		$detailFields->push( new TextField( 'LastVisited', 'Last Visits' ) ); 
		$detailFields->push( new TextField( 'GroupID', 'Group ID' ) ); 
		
		//$detailFields->push( new ComplexTableField($this, 'MembersVacancies', 'Vacancy', array('ID', 'vTitle'),array('ID', 'vTitle') ));

		//$controller, $name, $sourceClass, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = ""
		
		$sourceJoin = "LEFT JOIN Group_Members ON Member.ID = Group_Members.MemberID";
		//$tableList = new ComplexTableField($this, 'VacancyList', 'Vacancy', $fieldList, $detailFields, $filter, $sort);
		$tableList = new ComplexTableField($this, 'Member', 'Member', $fieldList, $detailFields, $filter,$sort, $sourceJoin );
		
		$tableList->setPopupCaption("Add / Edit Member");
		$fields = new FieldSet(
			new HiddenField( 'ID' ),
			$tableList
		);
		
		//$actions = new FormAction( 'doForm', 'Save Me');

		return new Form($this, 'EditForm', $fields);
		
	}

Avatar
iadawn

Community Member, 13 Posts

15 October 2008 at 4:03am

I am having a similar problem to this. Actually, it is pretty identical.

I need to extend the Newsletter functionality (don't ask!) and have included a NewsletterBlock class which Newsletters may have many of. So I have:

<?php
class NewsletterBlock extends DataObject {
	static $db = array(
		'Title'         => 'Varchar(255)',
		'Content'       => 'HTMLText',
		'ImagePosition' => "Enum( 'Left, Right', 'Left')",
	);
	
	static $has_one = array(
		'Image'      => 'Image',
		'Newsletter' => 'Newsletter',
	);

	function getCMSFields() {
		$fields = new FieldSet(
			new TextField( 'Title', _t('NewsletterBlock.Title', 'Title') ),
			new HTMLEditorField( 'Content', _t('NewsletterBlock.Title', 'Content') ),
			new ImageField( 'Image', _t('NewsletterBlock.Image', 'Image') ),
			new OptionsetField('ImagePosition', _t('NewsletterBlock.Image', 'Image position'), singleton( 'NewsletterBlock' )->dbObject('Imageposition')->enumValues() )
		);

		return $fields;
	}
	
}
?>

And I made the following additions to Newsletter.php:

	static $has_many = array(
		"Recipients" => "Newsletter_Recipient",
		"SentRecipients" => "Newsletter_SentRecipient",
		"Blocks"         => "NewsletterBlock",
	);

And, added the following into the getCMSFields method:

	$contentBlocks = new Tab(_t('Newsletter.ContentBlocks', 'Content Blocks'),
		$blockTable = new ComplexTableField(
			$controller       = $this,
			$name             = 'NewsletterBlock',
			$sourceClass      = 'NewsletterBlock',
			$fieldList        = array(
				'Title'   => _t('Newsletter.Title','Title'),
				'Content' => _t('Newsletter.Content','Content'),
			)
		)
	),

Trouble is when I put it all together and hit the nice big 'Add Newsletter Bloc' button in the Content Blocks tab I get the following error in the pop up:

Error is: FATAL ERROR: Form::callfieldmethod() Field 'NewsletterBlock' not found At line 633 in /Users/kevin/Sites/INSP/sapphire/forms/Form.php

I thought I would try the latest build just to see what would happen. In there I get the following error message:

I can't handle sub-URLs of a NewsletterAdmin object.

I am seriously stumped on this one, so any help would be appreciated!

Thanks

Kevin