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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Form Questions /

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

Validate form fields against databse

Go to End

10 Posts   2903 Views


Community Member, 83 Posts

30 November 2012 at 9:39am

hi dross,

do i understand this right, that you are updating the CardNumbers record right in the function checkVoucherandSourceCode() ?
This function was just for validating.
Setting Registered = '1' should be done after the form was successfully sent. So put it in function doRegister()

I just noticed that my validation rule was not complete. It didnt check for Registered = 0, but you added this already to the query.
Btw. what datatype is "Registered"? If you defined it as "Registered" => "Boolean", than you should use
Registered = 1 instead of Registered = '1'

Here some code for the doRegister function:

  function doRegister($data, $form) {
      //Create Member and log them in
      $Member = new UrbanMember();
      //Findo or create 'user' group
      if(!$userGroup = DataObject::get_one('Group', "Code = 'users'")) {
          $userGroup = new Group();
          $userGroup->Code = "users";
          $userGroup->Title = "Users";
      //Add member to user group
      // cancel voucher (we dont need to check for an unused voucher here. this has already been checked by the validator)
      $CardNumber = DataObject::get_one("CardNumbers", "VoucherNumber = '".Convert::raw2sql($data['VoucherNumber'])."' AND SourceCode = '".Convert::raw2sql($data['SourceCode'])."'");
      $CardNumber->Registered = 1;
      // Redirect to profile page
      if($ProfilePage = DataObject::get_one('EditProfilePage')) {
          return Director::redirect($ProfilePage->Link('?success=1'));


Community Member, 7 Posts

30 November 2012 at 9:45am

Got it. I'm really sort of a beginner so thanks a lot for you help. Works perfectly!

Go to Top