Welcome to the Cookbook

loading...

7.3.1.1 $options[‘type’]

This key is used to specify the type of form to be created. Valid values include ‘post’, ‘get’, ‘file’, ‘put’ and ‘delete’.

Supplying either ‘post’ or ‘get’ changes the form submission method accordingly.

<?php echo $form->create('User', array('type' => 'get')); ?>
 
//Output:
<form id="UserAddForm" method="get" action="/users/add">
  1. <?php echo $form->create('User', array('type' => 'get')); ?>
  2. //Output:
  3. <form id="UserAddForm" method="get" action="/users/add">

Specifying ‘file’ changes the form submission method to ‘post’, and includes an enctype of “multipart/form-data” on the form tag. This is to be used if there are any file elements inside the form. The absence of the proper enctype attribute will cause the file uploads not to function.

<?php echo $form->create('User', array('type' => 'file')); ?>
 
//Output:
<form id="UserAddForm" enctype="multipart/form-data" method="post" action="/users/add">
  1. <?php echo $form->create('User', array('type' => 'file')); ?>
  2. //Output:
  3. <form id="UserAddForm" enctype="multipart/form-data" method="post" action="/users/add">

When using ‘put’ or ‘delete’, your form will be functionally equivalent to a 'post' form, but when submitted, the HTTP request method will be overridden with 'PUT' or 'DELETE', respectively. This allows CakePHP to emulate proper REST support in web browsers.