如何在没有点击cakephp中的复选框的情况下发布数据?

时间:2013-02-15 09:52:17

标签: php cakephp cakephp-1.3 cakephp-2.0

我有选择框所在的表单并选择所有选项,我想发布所有数据而不点击复选框,我不想查看此页面,意味着如果用户进入注册页面,数据将被选中默认情况下,如何在任何视图中执行此操作? 这是我的观看代码

   <?php v_start($this);?>

<?php
    #if(element exits of controller-action)
    echo $this->element('validations/users/signup');    
?>

<script>
    function toggleChecked(status)
        {   
        jQuery(".new-checkbox input").each( function() {
                jQuery(this).attr("checked",status);
                }
            )
        }
</script>
<h1><span style="color:CornflowerBlue"><?php echo __l('Step1');?></span></h1>

<?php
$form = $this->FormManager;
echo $form->create('User',array_merge($form_options,array('default'=>true)));
?>

<table width = "100%">
    <tbody>
        <tr>
            <td>
                <?php echo $form->input('',array('id'=>'mark-all','onclick'=>'toggleChecked(this.checked)','type'=>'checkbox','label'=>'Select All Products' ));?>

                <?php echo $form->input('product_id', 
                                array(
                                    'multiple'=>'checkbox',
                                    'options'=>$products,
                                    'div'=>false,
                                    'class'=>'new-checkbox'
                                )   
                            );
                ?>

            </td>
        </tr>
        <tr>
        <td>
            <?php 
echo $this->FormManager->end(LBL_BTN_NEXT);
?>

        </td>
        </tr>
    </tbody>
</table>

我不想要这个页面,用户默认会选择数据。  这是我的控制器代码

        $products   =   $this
                    ->User
                    ->ProductsUser
                    ->Product
                    ->find('list',array(
                                'fields'    =>  'product_id,name',
                                    'conditions'=>array(
                                                'Product.is_visible'=>true
                                                )                       
                                        )
                            );
    $this->set('products',$products);
    if($this->request->is('post'))
        {   
            $this->Session->write('signUp.signUpProduct',$this->request->data['User']);
            $this->redirect(array('action'=>'signup_product'));
        }       
}

我怎么能这样做,提前谢谢。

1 个答案:

答案 0 :(得分:0)

attr()不会将true或false视为参数。

jQuery(this).attr("checked","checked"); // Correct usage of attr()

虽然我认为对于有利的prop()方法,attr已被弃用。

jQuery(this).prop("checked",status);

确实需要一个真实/错误的论点。 :) 希望这会有所帮助。