CakePHP Form questions: hidden fields & default values
I have searched the web, waisted a weekend on trying things, but need some expert advice to choo开发者_StackOverflow中文版se the best and safest solutions for CakePHP 1.3.10
In my users/add form, I have the following values that are in the Users table but do not need an input from the form. Nevertheless, when you bake an app, Cake will include them in the form:
- hitcount
- role (4 options loaded from Roles table).
What I want to do:
- I do not want to display hitcount and role in the form
- I want to give role the default value 'standard user' on every sign up
I can use 'hidden' to hide the hitcount and roles input and set default values in the database, but I heard that spyders can change the value of an hidden field and inject your database.
I am sure I am not the first with this setup. Please let me know how you guys did it. Thanks!
- Simply don't output the input field if you don't need it.
Set the value in the controller before saving:
if ($this->data) { $this->data['Model']['role'] = 'default role'; if ($this->Model->save($this->data)) ... }
精彩评论