We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Angular 4 boolean form values & Phalcon

I use phalcon & angular together. I have a form in angular:

<!--rest of form-->
<label class="radio-inline" *ngFor="let m of marriageCtrl">
            <input type="radio" formControlName="marriage" [value]="m.value">{{m.label}}
</label>

value is boolean: true/false. When I submit it to form, I get values in phalcon:

public function SaveAction() 
{
    $formValues = $this->request->getJsonRawbody();
    $person = new Person();
    foreach($formValues as $key=>$val)
    {
            $person->$key = $vale;

    }
    //Rest of Person model properties
    if($person->save() == true) {
        return ["message"=>"Person saved Successfully!"];
    }else {
        $message = '';
        foreach($person->getMessages() as $msg) {
            $message = $message.$msg->getMessage() 
        }
        return ['message'=>$message];
    }
}

It is ok for other properties but for marriage which is boolean returns:

marriage is required

But if I var_dump() person object, It shows:

["marriage"]=>
  bool(true)

What db backend are you using?

Mysql and marriage column is tinyint(1)



1.1k
Accepted
answer

It seems converting marriage column from TINYINT(1) to BIT solved problem!