views:

189

answers:

1

I'm building a site that requires multiple forms for the same model in varying numbers throughout a single page. These forms belong to an object with an id. Currently, since I can't figure out how to change the form ids, I'm stuck with a hole bunch of duplicate ids.

I'm looking for a way to append the object id to the form id so they're not invalid. I'm 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>
A: 
echo $form->create('Comment', array('url' => array('controller' => 'comments', 'action' => 'createComment'), "id" => "form_".$object['Object']['id']));

That should do the trick, I believe.

EDIT:

After review, this is what I used to get what you were asking:

echo($form->create('Comment', array('action' => 'createComment', "id" => "form_".$object['Object']['id'])));
Codeacula
Let me look over your code, then, because this works just fine for me:<?php echo($form->create("Option", array("id"=>"Test")));?>See: codeacula.com and view source.
Codeacula
Updated it. That's the form that's working for me. If it doesn't for you, it's beyond my knowledge with what's provided.
Codeacula
ah sorry. It does work. I had a sight moment of stupidity. I was looking at one of the inputs within the form, not the form itself. Wow I feel silly. Thanks for your help.
Robert Hurst
It happens to all of us.
Codeacula