Welcome to the Cookbook

loading...

7.3.1.3 $options[‘url’]

If the desired form action isn’t in the current controller, you can specify a URL for the form action using the ‘url’ key of the $options array. The supplied URL can be relative to your CakePHP application, or can point to an external domain.

<?php echo $form->create(null, array('url' => '/recipes/add')); ?>
// or
<?php echo $form->create(null, array('url' => array('controller' => 'recipes', 'action' => 'add'))); ?>


//Output:
<form method="post" action="/recipes/add">
 
<?php echo $form->create(null, array(
    'url' => 'http://www.google.com/search',
    'type' => 'get'
)); ?>
 
//Output:
<form method="get" action="http://www.google.com/search">
  1. <?php echo $form->create(null, array('url' => '/recipes/add')); ?>
  2. // or
  3. <?php echo $form->create(null, array('url' => array('controller' => 'recipes', 'action' => 'add'))); ?>
  4.  
  5. //Output:
  6. <form method="post" action="/recipes/add">
  7. <?php echo $form->create(null, array(
  8. 'url' => 'http://www.google.com/search',
  9. 'type' => 'get'
  10. )); ?>
  11. //Output:
  12. <form method="get" action="http://www.google.com/search">

Also check HtmlHelper::url method for more examples of different types of urls.