Deskripsi
How to use form helper
Required
1. Understand Model , Controller , Routes , view , etc
How To
1. Form helper always write in view.
2. Here's the minimal syntax helper form must have
$this->Form->create('model',array('url'=>array('controller'=>'myctrl','action'=>'myact',param1,..);
$this->Form->input('field',array(*attribute*));
$this->Form->submit('submit',array(*attribute*));
$this->Form->end();
3.Here's the attribute for input
- 'div'=>false/true
- 'label'=>false/true
- 'style'=>'your css here'
- 'required'=>'required' // show exception when field is empty on click submit
- 'maxlength'=>'50' //means 50 character
- 'type' => 'text/select/textarea/date/hidden'
- 'value' => 'abc' // fill the value for input object except select and date
* for attribute type='select', you must add attribute options, for example
$this->Form->input('field',array('type'=>'select','options'=>array('a','b','c')));
* for attribute type='date' , you can customize format date like this
$this->Form->input('field',array('type'=>'date','dateFormat' => 'DMY'));// it will display current date
but if you want using another value date instead current date you can write like this
this->Form->input('field',array('type'=>'date','dateFormat' => 'DMY','dateFormat' => 'DMY','selected' => date('Y-m-d',strtotime('3/19/2014 00:00:00')))); // why Y-m-d because without dateFormat DMY the default is YMD.
Post a Comment
Harap gunakan bahasa yang baik dan sopan, terima kasih