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.

Form Questions /

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

Custom Form redirects to a blank site


Go to End


3 Posts   3152 Views

Avatar
markus85

Community Member, 12 Posts

6 April 2009 at 5:14pm

Hi.
I created a form to update some data in a database. The first view of the site is fine but if I send the form via the automaticly generated button it will redirect me to a blank page. I looked into the source code of this blank page - it was empty, even no head tags or something like that- nothing.

Can anyone explain me this behavior?
I checked my sourcecode more than one time and didnt find a mistake but ... well maybe I´m overlooking something.

The whole thing is done by a subclass of Page and its Controller.
Here is a snippet of my Code, I also attached the whole file.



	/**
	 * Das Formular für die Seite
	 * Hier kann der Datensatz leicht manipuliert werden.
	 */
	function Form(){

		$auftrag = $this->getAuftrag();

		if($auftrag){

			// Daten für die Dropdownliste Kunde holen
			$kunden = DataObject::get('Kunde');
			if ($kunden){
				$kundenSources = $kunden->toDropDownMap('ID', 'Name');	// Datenaufbereite
			}

			$fields = new FieldSet(
				new TextField('Auftragsnummer', 'Auftragsnummer', $auftrag->Auftragsnummer),
				new TextField('Thema', 'Thema', $auftrag->Thema),
				new DateField('Startdatum', 'Startdatum', $this->DatumsWandler($auftrag->Startdatum)),
				new DateField('Enddatum', 'Enddatum', $this->DatumsWandler($auftrag->Enddatum)),
				new CheckboxField('Abgeschlossen', 'Abgeschlossen', $auftrag->Abgeschlossen),
				new DropdownField('KundeID', 'Kunde', $kundenSources, $value=$auftrag->KundeID)
			);


			$actions = new FieldSet(
				new FormAction('doAuftragUpdate', 'Auftrag aktualisieren')
			);;
			$validator = new RequiredFields(
				'Auftragsnummer',
				'Thema',
				'Startdatum',
				'Enddatum'
			);

			$form = new Form(
				$this,
				'Form',
				$fields,
				$actions,
				$validator
			);

			return $form;

		}
 	}


	 function doAuftragUpdate($data, $form){

	 	$auftrag = $this->getAuftrag();
	 	if($auftrag){
	 		$form->saveInto($auftrag);
	 		$auftrag->write();
	 		$form->sessionMessage('Der Auftrag wurde erfolgreich aktualisiert', 'good');
	 	}
		Director::redirectBack();
		return;

 	}


Avatar
Hamish

Community Member, 712 Posts

7 April 2009 at 9:25pm

Hey there,

That would indicate that Director::redirectBack() is not working. Are you sure it is getting that far? Have you turned on dev-mode? What if you try Director::redirect('some-random-url')?

Avatar
markus85

Community Member, 12 Posts

9 April 2009 at 2:53am

Its working.

I just add a else-conidtion in the funtion form()
Where I return a blank form