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 /

Create new form generate this error 'getviewer'


Reply


1373 Views

Avatar
int.gio

Community Member, 2 Posts

28 July 2010 at 10:40pm

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!!!