Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » Create new form generate this error 'getviewer'

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

Page: 1
Go to End
Author Topic: 1288 Views
  • int.gio
    Avatar
    Community Member
    2 Posts

    Create new form generate this error 'getviewer' Link to this post

    Hi,

    i create a new form with this code

    <?php
    class IscrizioneNewsletter extends Form {

    function __construct($controller, $name) {
    $fields = new FieldSet(

             // List your fields here
             new TextField("FirstName", "First name"),
             //new TextField("Surname"),
             new EmailField("Email", "Email address"),
             new CheckboxField("privacy","privacy")

          );

    $actions = new FieldSet(
    new FormAction('IscrizioneNewsletter', 'IscrizioneNewsletter')
    );

    $requiredFields = new RequiredFields("FirstName","privacy","Email"

           );

    parent::__construct($controller, $name, $fields, $actions);
    }

    function forTemplate() {
    return $this->renderWith(array(
    $this->class,
    'Form'
    ));
    }
       function IscrizioneNewsletter($data, $form) {

          $member = new Member();
          $form->saveInto($member);
          // See if the user email is already in the system
          if(DataObject::get_one('Member', "Email = '".$member->getField('Email')."'")) {
           Director::redirect('registration-failed-email-exists/');
          }else{
             $member->write();
          if($group = DataObject::get_one('Group', "ID = $this->defaultGroupID")) {

             $member->Groups()->add($group);
             Director::redirect('thanks-for-registering/');
          }else{
             Director::redirect('registration-failed/');

          }

          }

       }

    }
    ?>

    i call this form in the controller page

    class HomePage_Controller extends Page_Controller{

    ...

       function IscrizioneNewsletter() {
          return new IscrizioneNewsletter($this,'IscrizioneNewsletter');
       }

    }

    when i click the submit button i get this

    [User Error] Uncaught Exception: Object->__call(): the method 'getviewer' does not exist on 'IscrizioneNewsletter'
    POST /test/giovanni/projects/siriaonline.com/trunk/home/IscrizioneNewsletter

    Line 724 in /var/server/www/htdocs/test/giovanni/projects/siriaonline.com/trunk/sapphire/core/Object.php
    Source

    715             
    716             default :
    717                throw new Exception (
    718                   "Object->__call(): extra method $method is invalid on $this->class:" . var_export($config, true)
    719                );
    720          }
    721       } else {
    722          // Please do not change the exception code number below.
    723          
    724          throw new Exception("Object->__call(): the method '$method' does not exist on '$this->class'", 2175);
    725       }
    726    }
    727    
    728    // -----------------------------------------------------------------------------------------------------------------
    729    
    730    /**

    Trace

    * Object->__call(getViewer,Array)
    * IscrizioneNewsletter->getViewer(IscrizioneNewsletter)
    Line 155 of Controller.php
    * Controller->handleRequest(SS_HTTPRequest)
    Line 199 of ContentController.php
    * ContentController->handleRequest(SS_HTTPRequest)
    Line 67 of ModelAsController.php
    * ModelAsController->handleRequest(SS_HTTPRequest)
    Line 283 of Director.php
    * Director::handleRequest(SS_HTTPRequest,Session)
    Line 127 of Director.php
    * Director::direct(/home/IscrizioneNewsletter)
    Line 127 of main.php

    Can anyone help me?

    Thanks!!!

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