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.

Form Questions /

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

$form is undefined - but why? ..by SalvaStripe


Go to End
Reply


2 Posts   2743 Views

Avatar
SalvaStripe

Community Member, 89 Posts

18 February 2009 at 12:01am

Edited: 18/02/2009 12:16am

hey guys,

i get this error:

Notice: Undefined variable: form in /srv/www/vhosts/domain.de/subdomains/sifa/httpdocs/mysite/code/MUPage.php on line 68 Fatal error: Call to a member function saveInto() on a non-object in /srv/www/vhosts/marketingundpartner.de/subdomains/sifa/httpdocs/mysite/code/MUPage.php on line 68

and this is the code of my form:

<?php
class MUPage extends Page {
	static $db = array(
	);
	static $has_one = array(
	);
	static $defaults = array(
	);	
}
 
class MUPage_Controller extends Page_Controller {

	function init() {
		parent::init();
		
//		Requirements::themedCSS("memberupload");
	}

	function AlbumCreateForm() {
			$fieldset = new FieldSet(
				new TextField(
					$name = "Name",
					$title = "Albumname",
					$value = ""
				),
				new TextareaField(
					$name = "Desc",
					$title = "Beschreibung",
					$rows = 8,
					$cols = 3,
					$value = ""
				),
		 		new HiddenField (
					$name = "Status",
					$title= "status",
					$value = "0"
				),
		 		new HiddenField (
					$name = "OwnerID",
					$title= "test",
					$value = Member::currentUserID()
				),
		 		new HiddenField (
					$name = "Date",
					$title= "Datum",
					$value = time()
				)
			);

		$actions = new FieldSet(
			new FormAction('AlbumCreate', 'Erstellen')
		);
		
		return new Form($this, 'AlbumSenden', $fieldset, $actions);
	}
	
	function AlbumSenden($data, $form) {
		$submission = new MUAlbum();
		$form->saveInto($submission);
		$submission->write();
		
		Director::redirectBack();
	}	
	
}
  
?>

THE FORM IS SHOWN, I GET THE ERROR AFTER CLICKING THE SEND BUTTON..

hmm.. i already did many form like this.. i cant find the error. Why the error says: "Notice: Undefined variable: form... ..."
Why is FORM undefined?

Avatar
SalvaStripe

Community Member, 89 Posts

18 February 2009 at 12:38am

Edited: 03/03/2009 4:36am

okay now it works :D

$actions = new FieldSet(
new FormAction('**HERE MUST NAME OF THE FUNCTION TO WRITE**', 'Erstellen')
);

return new Form($this, '**HERE MUST NAME OF THIS FUNCTION**', $fieldset, $actions);
}