php - 如果通过按钮访问页面,请勾选复选框
问题描述
寻求一些帮助以了解如何添加以下功能:
我的 WP 网站上有一个联系页面,其中有一个联系 7 表格和一个用于注册时事通讯的复选框。
可以通过两种方式访问联系页面 - 显然是通过菜单,但主页上还有一个“为我注册时事通讯”按钮,当点击该按钮时,当前也会将用户带到联系页面。我想这样当用户点击主页上的按钮时,它不仅会将他/她带到联系页面,而且还会自动勾选那里的复选框。如果用户通过菜单或任何其他方式访问联系页面,我不希望自动勾选复选框。
我想我正在寻找一些 php 逻辑,但任何想法都值得赞赏。
解决方案
Add PHP GET string to button link then read that on other side and make logic like:
if page is contact-page.php
, then on button add link contact-page.php?button=true
on contact-page.php
read that ?button=true
with PHP:
if (isset($_GET["button"])) {
//echo that checkbox checked
}else{
//echo that checkbox not checked
}
or in JS:
if (window.location.href.indexOf("button") > -1) {
//check checkbox with JS
}
Other option is that you use JS localStorage , when you click a button set localStorage
button: true
, then read that on contact-page.php
and if its true check checkbox with JS
推荐阅读
- mysql - 运行优化命令时,它会重建表,那么数据库中需要多少额外空间?
- html - 如何使边框和 z-index 保持到过渡结束?
- c# - 循环故障时,随机积分器仅在第一次工作
- javascript - MSIToken 中的 Azure 日期解析问题
- ios - 关于如何在与 CloudKit 同步的 Core Data 中存储 mp3 和图像文件的建议
- php - 如何在 WooCommerce 4+ 中为产品添加自定义库存状态
- python - 使用 while 循环获取 Panda DataFrame 中的列值
- sapui5 - 使用 HBox 容器和继承但自定义的事件扩展控制
- javascript - Nuxt 2.x:添加 babel 的转换插件,适用于导入的 node_module 文件
- hazelcast - 集群 Vert.x 服务时,集群的 EventBus 处理程序是否会传播到新的加入节点?