postLink generates invalid code at CakePHP 2.3 -
i using cakephp 2.3
i have 2 environments have web application. @ testing environment exact same version of application (all files same) having problem form->postlink method.
it shows error on javascript console:
uncaught typeerror: object # has no method 'submit' users:119 onclick
comparing resulting html both environments can notice attributes name , id generated method repeated more once in same page (which shouldn't that).
this code use generate post links:
foreach($users $user){ $delete = $this->form->postlink(__('delete'), array('action' => 'delete', $user['user_id']), __('are sure want delete %s?', $user['user_id'])); } this problematic generated html repeated values id , name can see:
<!-- link 1 --> <form action="delete/1/" name="post_51e8019d095f1" id="post_51e8019d095f1" style="display:none;" method="post"> <input type="hidden" name="_method" value="post"/> </form> <a href="#" onclick="if (confirm('are sure want delete blabla?')) { document.post_51e8019d095f1.submit(); } event.returnvalue = false; return false;">delete</a> <!-- link 2 --> <form action="delete/2/" name="post_51e8019d095f1" id="post_51e8019d095f1" style="display:none;" method="post"> <input type="hidden" name="_method" value="post"/> </form> <a href="#" onclick="if (confirm('are sure want delete blabla22?')) { document.post_51e8019d095f1.submit(); } event.returnvalue = false; return false;">delete</a> why happening? related configuration of web server somehow? don't see explanation it...
thanks.
the problem caused bug in iis 7.0.6000.16386 , php function uniqid pointed out here.
i using different version in both environments ( iis 7.0.6000.16386 vs iis 7.5.7600.16385) , cause of problem.
in order solve modified file lib/cake/view/helper/formhelper.php chaning line $formname = uniqid('post_'); inside postlink function to:
$formname = uniqid('post_', true); that adds more entropy , documentation says:
if set true, uniqid() add additional entropy (using combined linear congruential generator) @ end of return value, increases likelihood result unique.
update
ended having add 1 more change due problems javascript in forms. added 1 more line after $formname = uniqid('post_', true); looks like:
$formname = uniqid('post_', true); $formname = str_replace('.', '', $formname);
Comments
Post a Comment