[Cakephp] Basic Form

Deskripsi
       Form digunakan sebagai interaksi antara user dan system, interaksi berupa inputan yang digunakan untuk berbagai macam keperluan, seperti register , login , penyimpanan data , etc.

Howto
<table border="0" width="500px;" style="margin-left:10px;" cellspacing="2px;">

            <?php echo $this->Form->create('MODEL', array(
                                   'id'=>'ID_FORM',
                                   'url'=>array(
                                                     'controller'=>'controller',
                                                      'action'=>'action')))
            ?>

            <td>USERNAME</td>
            <td style="text-align:left;padding-left:4px;">
            <?php echo $this->Form->input('USERNAME',array('label'=>false,'style'=>'width:370px'))
             ?>
            </td>

        <?php echo $this->Form->submit('submit_button')?>
        <?php echo $this->Form->end()?>

</table>

Explanation :
* normally you don't need the table, this only sample my code when using form in intranet application.

to create form :  $this->Form->create(MODEL,array(OPTION)); // must have at least 1
to create input : $this->Form->input(MODEL,array(OPTION));
to create submit button : $this->Form->submit('submit_button'); // must have at least 1
to create end tag : $this->Form->end() // must have at least 1

for OPTION , you can read online manual.

after you submit form , you form data exist in variable data in controller, how to call :

$this->data;

variable data is an array variable so if you want to see the value :

print_r($this->data);

if you want to change the value :

$this->request->data['xxx']['zzz'] = 'this is the new one'

if you want to save the database :

$this->model->save($this->data);
  

Post a Comment

Harap gunakan bahasa yang baik dan sopan, terima kasih