Welcome to the Cookbook

loading...

7.3.3.1 Field naming convention

The Form helper is pretty smart. Whenever you specify a field name with the form helper methods, it'll automatically use the current model name to build an input with a format like the following:

<input type="text" id="ModelnameFieldname" name="data[Modelname][fieldname]">
  1. <input type="text" id="ModelnameFieldname" name="data[Modelname][fieldname]">

You can manually specify the model name by passing in Modelname.fieldname as the first parameter.

echo $form->input('Modelname.fieldname');
  1. echo $form->input('Modelname.fieldname');

If you need to specify multiple fields using the same field name, thus creating an array that can be saved in one shot with saveAll(), use the following convention:

<?php 
   echo $form->input('Modelname.0.fieldname');
   echo $form->input('Modelname.1.fieldname');
?>

<input type="text" id="Modelname0Fieldname" name="data[Modelname][0][fieldname]">
<input type="text" id="Modelname1Fieldname" name="data[Modelname][1][fieldname]">
  1. <?php
  2. echo $form->input('Modelname.0.fieldname');
  3. echo $form->input('Modelname.1.fieldname');
  4. ?>
  5.  
  6. <input type="text" id="Modelname0Fieldname" name="data[Modelname][0][fieldname]">
  7. <input type="text" id="Modelname1Fieldname" name="data[Modelname][1][fieldname]">