Create a Form in CakePHP

To create a form in CakePHP we can use careate() method.
Let’s take an example with cake1 as a root folder and users is a table.

<?php echo $this->Form->create(); ?>

Above code will render following output in view:

<form action=”/cake1/users/” id=”UserIndexForm” method=”post” accept-charset=”utf-8″>

In create function parameters are optional. If we call this function without parameters, it will take default method POST, default id name of model and name of controller action. Like above.

Another Example with parameters:

<?php echo $this->Form->create(‘admin’,array(‘action’=>’login’)); ?>

Output in view:

<form action=”/cake1/admins/login” id=”adminLoginForm” method=”post” accept-charset=”utf-8″>

To close the form tag, code:

<?php echo $this->form->end(); ?>

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.