Jump to:

2002 Posts in 1422 Topics by 616 members

Form Questions

SilverStripe Forums » Form Questions » $form is undefined - but why? ..by SalvaStripe

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

Page: 1
Go to End
Author Topic: 2381 Views
  • SalvaStripe
    Avatar
    Community Member
    89 Posts

    $form is undefined - but why? ..by SalvaStripe Link to this post

    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?

  • SalvaStripe
    Avatar
    Community Member
    89 Posts

    Re: $form is undefined - but why? ..by SalvaStripe Link to this post

    okay now it works

    $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);
    }

    2381 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.