Thursday, April 28, 2011

Why does CakePHP bork when I use jquery to modify values of hidden inputs?

I'm using cakephp to build a survey and want to use javascript (specifically jquery as it's used elsewhere) to modify some hidden inputs.

To be clear, commenting out the offending lines of jquery allows cake to do it's thing properly. But when the values are modified with jquery, this happens:

(default) 2 queries took 2 ms

To take just one of the hidden inputs in question, here's the relevant code:

<?php echo $form->hidden('bigLayout', array('value'=>'1')); ?>

<script> $('#ResponseBigLayout').val('0');</script>

Additionally, I can use Firebug to replicate the error using just that line of javascript. Using Tamper Data doesn't reveal anything obvious. Lastly, changing the default value in the php doesn't cause the error.

Anyone know what might be going on here?

From stackoverflow
  • Try using

    <?php echo $form->hidden('bigLayout', array('value'=>'1','secure'=>false)); ?>


    <?php echo $form->hidden('bigLayout', array('value'=>'1','secure'=>'false')); ?>

    From the source (FormHelper: hidden())it looks like CakePHP for hidden inputs uses secure = true by default.

    Tom Wright : Unfortunately, that didn't change anything. Strangely though, when I used 'secure'=>'false' and $('#ResponseBigLayout').val('1'); I get a different error with 0 queries. Is this a useful clue to anyone?
  • If I do modify form values (for hidden) or attributes (i.e. disabled) then in controller in beforeFiler I use something like this:

    function beforeFilter() {
        if ($this->action == 'add') {
            $this->Security->enabled = false;


Post a Comment