Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » Validate form fields against databse

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

Page: 1 2
Go to End
Author Topic: 1357 Views
  • lx
    Community Member
    82 Posts

    Re: Validate form fields against databse Link to this post

    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'));


  • dross
    Community Member
    7 Posts

    Re: Validate form fields against databse Link to this post

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

Page: 1 2
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.