Jump to:

2002 Posts in 1422 Topics by 616 members

Form Questions

SilverStripe Forums » Form Questions » Custom Form redirects to a blank site

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

Page: 1
Go to End
Author Topic: 1886 Views
  • markus85
    Avatar
    Community Member
    12 Posts

    Custom Form redirects to a blank site Link to this post

    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;

       }

    Attached Files
  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Custom Form redirects to a blank site Link to this post

    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')?

  • markus85
    Avatar
    Community Member
    12 Posts

    Re: Custom Form redirects to a blank site Link to this post

    Its working.

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

    1886 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.