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.

Data Model Questions

Error writing Member object in SS3


Reply

3 Posts   493 Views

Avatar
solartom

15 August 2012 at 10:02am (Last edited: 19 August 2012 10:59am), Community Member, 4 Posts

Hello,

I'm new to silverstripe and I decided to try out Silverstripe 3. I created a basic registration form and everything worked in Silverstripe 2.4 but I get an error in Silverstripe 3. I probably missed something that needs to be changed to work in 3 but I haven't been able to find it so far.

Any help would be greatly appreciated

Here's the code:

class ArtistRegPage extends Page
{
   static $db = array();
   static $has_one = array();
}

class ArtistRegPage_Controller extends Page_Controller
{
   function form()
   {
      $fields = new FieldList(
      new TextField('FirstName','First Name'),
      new TextField('Surname','Last Name'),
      new EmailField('Email','Email Address'),
      new ConfirmedPasswordField('Password')
      );
      
      $actions = new FieldList(new FormAction('doArtistRegister','Submit'));
      $validator = new RequiredFields('FirstName', 'SurName', 'Email', 'Password');
      $form = new Form(
            $this,
            'Form',
            $fields,
            $actions,
            $validator
            );
      return $form;
   }
   
   function doArtistRegister($data, $form)
   {
      $artist = new Artist();
      $form->saveInto($artist);
      $form->sessionMessage('Form successfully submitted', 'Good');
      $artist->write();
      return $this->redirectBack();
   }
}


Note: It works fine if comment out $artist->write(). Also the same problem occurs if I use Member instead of Artist.

Thanks,
Tom

Avatar
Willr

17 August 2012 at 8:19pm Forum Moderator, 5511 Posts

What is the error message you get?

Avatar
solartom

18 August 2012 at 9:33am Community Member, 4 Posts

I did some more tracking down of the error and found out it was a validation error. I was using an existing email address. I will need to read up more on validation to make sure the error is correctly reported to the user.

Thanks,
Tom