title: Multiple edit forms for the same model in CakePHP 2.4
body: <p>I have a scenario in which I have two models, profile and education, with a Profile hasMany Education relationship.</p>
  
  <p>Then I have a view where I want to have multiple forms:</p>
  
  <ul>
  <li>One edit form for each Education entry of the user's profile.</li>
  <li>One form to add a new entry.</li>
  </ul>
  
  <p>The problem here is that I want the edit forms to be filled with the data of each entry. 
  <strong>Any ideas on how I can implement this?</strong> </p>
  
  <p>CakePHP documentation states that: </p>
  
  <blockquote>
    <p>The FormHelper uses the $this->request->data property to automatically detect whether to create an add or edit form. If $this->request->data contains an array element named after the form’s model, and that array contains a non-empty value of the model’s primary key, then the FormHelper will create an edit form for that record</p>
  </blockquote>
  
  <p>I already implemented successfully an edit form but in a case where I only had one form.</p>
  
  <p>Right now I have something like this:</p>
  
  <p>EducationController.php</p>
  
  <pre><code>public class EducationController extends AppController{
  
  /* (...) */
  
  public function edit_index(){
  
  $user_id = $this-&gt;Auth-&gt;user('id');
  
  $profile = $this-&gt;Profile-&gt;find('first', array('conditions' =&gt; array('Profile.user_id' =&gt; $user_id)));
  
  $this-&gt;set('profile', $profile);
  
  $this-&gt;request-&gt;data = $profile;
  
  }
  
  /* (...) */
  
  }
  </code></pre>
  
  <p>As for the view file...</p>
  
  <pre><code> &lt;?php
      foreach ($profile['Education'] as $key =&gt; $value) {
          ?&gt;
          &lt;div class="history-sub-menu" id="history-1"&gt;
              &lt;p&gt; &lt;?php echo $value['education'] . ' - ' . $value['school'] ?&gt; &lt;/p&gt;
              &lt;?php echo $this-&gt;Html-&gt;image("arrow_bot.png") ?&gt;    
          &lt;/div&gt;
          &lt;?php
          /*
           * Prints the form for editing... the id of the education entry being edited goes
           * as a parameter
           */
          echo $this-&gt;element('education_edit_form', array('hidden' =&gt; true, 'id' =&gt; $value['id']));
          ?&gt;
          &lt;?php
      }
      ?&gt;
  
      &lt;div class="add-sub-menu"&gt;
          &lt;p&gt;&lt;?php echo $add_another_position ?&gt;&lt;/p&gt;
  &lt;?php echo $this-&gt;Html-&gt;image("plus_blue.png") ?&gt;
      &lt;/div&gt;
  
      &lt;?php
      /*
       * Prints the form for adding... as no parameter is given as the id
       * the form assumes it is a form for adding.
       */
  
      echo $this-&gt;element('education_edit_form', array('hidden' =&gt; true));
      ?&gt;
  </code></pre>
  
  <p>The 'education_edit_form' element:</p>
  
  <pre><code>    &lt;?php
  
  /* Prints a form for creating or editing an user academic entry.
   * 
   * In case of edit form a variable id must be set with the identifier of 
   * the academic entry being creted.
   * 
   * Other Paramaters:
   *  hiddden - Set to true if the form should be hidden by default
   *  
   */
  
  
  if (isset($hidden)) {
      ($hidden) ? $hidden = 'display:none' : $hidden = '';
  } else {
      $hidden = '';
  }
  
  if (isset($id)){
     $id_string = ".$id."; 
  }else{
      $id_string = ".";
  }
  
  
  
  /* String Constants */
  
  $input_eduschool_default_text = __("School");
  $input_edudegree_default_text = __("Degree");
  $input_edufield_default_text = __("Field/s of Education");
  $input_edugrade_default_text = __("Grade (What qualification/s did you obtain?");
  $input_edudescription_default_text = __("Description");
  $input_edustartdate_default_text = __("Start Date");
  $input_eduenddate_default_text = __("End Date");
  
  $submit_button_text = __("Save");
  ?&gt;
  
  
  
  &lt;?php echo $this-&gt;Form-&gt;create('Education', array('controller' =&gt; 'Education', 'action' =&gt; 'add', 'class' =&gt; 'main', 'style' =&gt; '$hidden')); ?&gt;  
  
  
  &lt;?php
  
  echo $this-&gt;Form-&gt;input('Education'.$id_string.'school', array(
      'class' =&gt; 'white large',
      'placeholder' =&gt; $input_eduschool_default_text,
      'id' =&gt; 'edu-school',
      'label' =&gt; false,
      'div' =&gt; false,
      'type' =&gt; 'text'
  ));
  ?&gt;
  &lt;?php
  
  echo $this-&gt;Form-&gt;input('Education'.$id_string.'education', array(
      'class' =&gt; 'white large',
      'placeholder' =&gt; $input_edudegree_default_text,
      'id' =&gt; 'edu-education',
      'label' =&gt; false,
      'div' =&gt; false,
      'type' =&gt; 'text'
  ));
  echo $this-&gt;Form-&gt;input('Education'.$id_string.'study_field', array(
      'class' =&gt; 'white large',
      'placeholder' =&gt; $input_edufield_default_text,
      'id' =&gt; 'edu-field',
      'label' =&gt; false,
      'div' =&gt; false,
      'type' =&gt; 'text'
  ));
  echo $this-&gt;Form-&gt;input('Education'.$id_string.'qualification', array(
      'class' =&gt; 'white large',
      'placeholder' =&gt; $input_edugrade_default_text,
      'id' =&gt; 'edu-grade',
      'label' =&gt; false,
      'div' =&gt; false,
      'type' =&gt; 'text'
  ));
  echo $this-&gt;Form-&gt;input('Education'.$id_string.'start_date', array(
      'class' =&gt; 'white one-third',
      'placeholder' =&gt; $input_edustartdate_default_text,
      'id' =&gt; 'edu-start-date',
      'label' =&gt; false,
      'div' =&gt; false,
      'type' =&gt; 'text'
  ));
  echo $this-&gt;Form-&gt;input('Education'.$id_string.'end_date', array(
      'class' =&gt; 'white one-third',
      'placeholder' =&gt; $input_eduenddate_default_text,
      'id' =&gt; 'edu-end-date',
      'label' =&gt; false,
      'div' =&gt; false,
      'type' =&gt; 'text'
  ));
  
  echo $this-&gt;Form-&gt;input('Education'.$id_string.'description', array(
      'class' =&gt; 'white large',
      'placeholder' =&gt; $input_edudescription_default_text,
      'id' =&gt; 'edu-notes',
      'label' =&gt; false,
      'div' =&gt; false,
      'type' =&gt; 'textarea',
      'rows' =&gt; '5'
  ));
  ?&gt;
  
  
  &lt;?php
  
  echo $this-&gt;Form-&gt;submit($submit_button_text, array(
      'class' =&gt; 'intro_submit',
      'type' =&gt; 'submit'
  ));
  
  echo $this-&gt;Form-&gt;end();
  ?&gt;
  </code></pre>
  
  <p>Note please that this is a draft... I still have to implement the actions to process the form data and do some additional validations in the 'education_edit_form' element. But right now I only want to know how to fill the edit forms with the values from the entry being edited.</p>
  
  <p>Thank you in advance</p>