2

I have created a model using the following code:

type UserProfile struct {
    Id                  int             `orm:"auto"`
    Name                string          `orm:"size(100)"`
    Email               string          `orm:"size(100)"`
    Type                string          `orm:"size(30)"`
    Admin               bool
    Car                 []*Car          `orm:"reverse(many)"`
}

Is there any way I can render a form directly using this structure? I think valid:required rakes care of validation, but how do we control form rendering.

Siddharth Gupta
  • 1,573
  • 9
  • 24

1 Answers1

7

In controller:

func (this *AddController) Get() {
   this.Data["Form"] = & UserProfile{}
   this.TplNames = "index.tpl"

}

In template :

<form action="" method="post">
    {{.Form | renderform}}
</form>
Kritner
  • 13,557
  • 10
  • 46
  • 72
Kyaw Myint Thein
  • 540
  • 4
  • 10
  • Is there a way to use bootstrap css with the forms ? Otherwise the generated form is very basic html, thank you. – user1619524 May 05 '18 at 16:47