I have a group of tests in my system. It is possible for a test to be paused. On the index page of my test controller, I use the following code to display the tests.
<table>
<tr><th>ID</th><th>Name</th><th>Updated</th><th>Actions</th></tr>
<?php foreach ($tests as $test): ?>
<tr>
<td>
<?php echo $test['Test']['id']; ?>
</td>
<td class="actions">
<?php
$status = ($test['Test']['is_paused'] == 1) ? 'Un-pause' : 'Pause';
echo $this->Form->postLink($status, array('controller'=>'tests', 'action' => 'pause', $test['Test']['id'], 'admin' => 1), array('confirm'=>'Are you sure?') );
?>
<?php
echo $this->Html->link('Edit', array('controller'=>'tests', 'action' => 'edit', 'admin'=>1, $test['Test']['id']));
?>
<?php
echo $this->Form->postLink('Delete', array('controller'=>'tests', 'action' => 'delete', $test['Test']['id'], 'admin'=>1), array('confirm'=>'Are you sure?') );
?>
</td>
</tr>
<?php endforeach; ?>
</table>
This generates a list of tests and provides some action functions for each one using postlink from the cakephp form helper. The one that is causing problems is the pause button. Sometime when clicked it throws the following error.
Uncaught TypeError: Object #<HTMLCollection> has no method 'submit'
This error almost never occurs on the first time pause is clicked. Pause can be toggled so this error usually pops up after pause has been toggled a few time. I'm not super up on my JS and since the JS for this is automatically built, I'm not sure how to fix this. The pause button will do nothing when this issue occurs and I'm not even sure where to start debugging this. Thank you to anyone who helps.
UPDATE: This is the html code that is being rendered in the browser by the postlink:
<form action="/admin/tests/pause/5" name="post_521370eb05d3f" id="post_521370eb05d3f" style="display:none;" method="post">
<input type="hidden" name="_method" value="POST">
</form>
<a href="#" onclick="if (confirm('Are you sure?')) { document.post_521370eb05d3f.submit(); } event.returnValue = false; return false;">Un-pause</a>
It looks like the code document.post_521370eb05d3f.submit(); is the problem, and if I had to guess, I think for some reason document.post_521370eb05d3f does not have a submit method. I'm not sure how to fix that though.