首页 \ 问答 \ 发布未选中的复选框(POST unchecked HTML checkboxes)

发布未选中的复选框(POST unchecked HTML checkboxes)

我有一个加载复选框是默认检查。 我的用户可能会取消选中一些复选框(如果有),并留下其余的复选框。 有没有办法得到没有在窗体帖子中检查的复选框,而不是检查的复选框?


I've got a load of checkboxes that are checked by default. My users will probably uncheck a few (if any) of the checkboxes and leave the rest checked.

Is there any way to make the form POST the checkboxes that are not checked, rather than the ones that are checked?


原文:https://stackoverflow.com/questions/1809494
更新时间:2023-03-20 13:03

最满意答案

说实话,JsHelper毫无用处。 我甚至没有理解它,我只是像往常一样在我的网站中包含JavaScript,但使用Cake的方法将其保留在框架内。

示例布局会在<head>包含jQuery,如下所示:

应用程序/浏览/设计/ default.thtml中

<head>

<?php
    // Include jQuery
    echo $this->Html->script('jquery-1.8.2.min');

    // Want to send some glabal values to your scripts?
    $this->Js->set(array(
        'TEST' => 'Hello World',
        'ROOT' => $this->Html->url( '/', true)
    ));
    echo $this->Js->writeBuffer(array('onDomReady' => false));

    // Include any other scripts you've set
    echo $this->fetch('script');
?>

</head>

然后在您的视图中,您可能希望包含该页面的特定脚本:

应用程序/视图/页/ test.ctp

<?php echo $this->Html->script('test.js'); ?>

您只需将所有JavaScript保存在外部脚本中:

应用程序/根目录/ JS / test.js

$(document).ready(function() {

    /**
     * Alert the value we set in our layout.  All JS vars that have been
     * set are available in your JavaScript via the window.app object.
     */
    alert(window.app.TEST + ' sent from ' + window.app.ROOT);

});

JsHelper is pretty useless to be honest. I don't even bother with it properly, I just include JavaScript in my site as I would normally, but using Cake's methods to keep it within the framework.

Example layout would have jQuery included in the <head> like this:

app/View/Layouts/default.ctp

<head>

<?php
    // Include jQuery
    echo $this->Html->script('jquery-1.8.2.min');

    // Want to send some glabal values to your scripts?
    $this->Js->set(array(
        'TEST' => 'Hello World',
        'ROOT' => $this->Html->url( '/', true)
    ));
    echo $this->Js->writeBuffer(array('onDomReady' => false));

    // Include any other scripts you've set
    echo $this->fetch('script');
?>

</head>

Then in your view, you might want to include a specific script for that page:

app/View/Pages/test.ctp

<?php echo $this->Html->script('test.js'); ?>

And you just keep all your JavaScript as usual in an external script:

app/webroot/js/test.js

$(document).ready(function() {

    /**
     * Alert the value we set in our layout.  All JS vars that have been
     * set are available in your JavaScript via the window.app object.
     */
    alert(window.app.TEST + ' sent from ' + window.app.ROOT);

});

相关问答

更多
  • CakePHP只是php。 正如大多数正确完成的php应用程序最近它配备了作曲家 。 我建议你至少阅读它手册的基础知识。 Composer是一个很棒的工具。 git clone cd composer install 如果您启动一个新的 Cake应用程序,官方文档也会告诉您如何: composer create-project --prefer-dist cakephp/app [app_name] 如果你想自动化一些东西, 作曲家会为你提供回调脚本 。 它们允许您在 ...
  • 说实话,JsHelper毫无用处。 我甚至没有理解它,我只是像往常一样在我的网站中包含JavaScript,但使用Cake的方法将其保留在框架内。 示例布局会在包含jQuery,如下所示: 应用程序/浏览/设计/ default.thtml中 Html->script('jquery-1.8.2.min'); // Want to send some glabal values to ...
  • 这可能是由于文件末尾有空格 如果在'?>'标记后面有空格,请检查您的文件,它会将其重定向到空白页面 或者您可以删除'?>'(关闭php标记)以删除此问题。 Answer Found: the zip extraction was not proper all i did was to extract the zip file again and ran my code and hurray... it worked well
  • 套管很重要,它应该是: 'datasource' => 'Database/Mysql' 并不是: 'datasource' => 'Database/MySQL' Casing matters, it should be: 'datasource' => 'Database/Mysql' And not: 'datasource' => 'Database/MySQL'
  • 首先, 文档为jquery中的complete选项指定了这一点 请求完成时要调用的函数(执行成功和错误回调之后)。 因此,无论是成功还是错误,它都会被调用。 您需要更改complete并success (如果您希望(但建议)) error来执行您想要的fadeOut,因为complete将始终在ajax调用后执行。 现在,另一件事。 你必须记住,即使控制器中的save有验证错误而且没有保存,ajax调用也会成功。 为什么? 因为带动作的连接将是正常的,并且控制器中没有可怕的错误。 因此,在ajax调用的su ...
  • 默认情况下,脚本会被缓存,您必须显式打印缓存。 要在每个页面的末尾执行此操作,请在结束标记之前包含此行: echo $this->Js->writeBuffer(); // Write cached scripts 我在Layouts文件夹中的default.ctp末尾使用它 By default scripts are cached, and you must explicitly print out the cache. To do this at the end of each page, incl ...
  • FWIW,我从不使用任何javascript助手,除了写include,即 link('aJavascriptFile') ?> 我会拉着我的头发试图找出为什么一些jQuery插件无法工作,如果它全部包含在帮助器中。 您不必使用帮助者 - 他们可以帮助您。 有时人们会有点疯狂,并开始为那些真正无法证明额外代码重量的东西创建帮手。 只需将其编码为“旧方式”并保持理智。 FWIW, I never use any of the javascript helpers ...
  • /// function to show magazines data table $('#add_researches_button').click(function() { $("input[name='bstock_researchs_id[]']:checked").each(function(i) { val[i] = $(this).val(); }); $.ajax({ type: "POST", ...
  • 转到app / webroot并打开index.php文件,找到定义函数CAKE_CORE_INCLUDE_PATH,并将值更改为您的路径。 /** * The absolute path to the "cake" directory, WITHOUT a trailing DS. * * Un-comment this line to specify a fixed path to CakePHP. * This should point at the directory containing ...
  • 您需要了解它了解模型 - 视图 - 控制器,CakePHP 正如他们的名字所描述的那样,使用MVC框架,您可以分离您的视图,控制器和模型(处理查询的快捷方式)。 这是处理更复杂项目的好方法。 此外,还有很多东西(html助手,表单助手等)可以帮助您更轻松地完成工作。 You need read about it Understanding Model-View-Controller, CakePHP As their name describe it, with an MVC framework you c ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)