How to make cakePHP form helper "create" action use a user id?

I am creating a website that requires several forms for the same model in different quantities on one page. These forms belong to the object with id. Currently, since I cannot figure out how to change form identifiers, I am stuck in a bunch of duplicate identifiers.

I am looking for a way to add an object identifier to a form identifier so that they are not invalid. I prefer to write my own javascript, so I will not use the ajax helper.

<?php

/**
 * This is a simplified example of what I am trying to do.
 */

?>

<div id="objects">
  <?php foreach($objects as $object): ?>
    <div class="object">
      <?php echo "this is object {$object['Object']['id']}"?>
      <?php
        //The following element would show a number of comments the object owns
        echo $this->element('object_comments_loop', array('comments' => $object['Object']['Comments']);
      ?>
      <div class="comment">
        <?php
          //each object has a form.
          //TODO: this is where the id issue comes into play.

          echo $form->create('Comment', array('url' => array('controller' => 'comments', 'action' => 'createComment'));
          echo $form->hidden('object_id', array('value' => $object['Object']['id']));
          echo $form->input('comment_body', array('label' => __('comment', true), 'type' => 'text'));
          echo $form->end(__('comment_submit', true));
        ?>
      </div>
    </div>
  <?php endforeach; ?>
</div>
+5
source share
1 answer
echo $form->create('Comment', array('url' => array('controller' => 'comments', 'action' => 'createComment'), "id" => "form_".$object['Object']['id']));

That should do the trick, I suppose.

EDIT:

, , , , :

echo($form->create('Comment', array('action' => 'createComment', "id" => "form_".$object['Object']['id'])));
+4

All Articles