【问题标题】:How can one pre-check a checkbox after a specific date and time?如何在特定日期和时间后预先选中复选框?
【发布时间】:2013-12-13 00:19:47
【问题描述】:

我想在特定日期和时间后自动添加一个包含滞纳金的表格。

我们使用的脚本要求表单上的每个项目都有一个复选框和一个金额字段。因此,延迟费用有一个复选框,并且在签到时,$ 25出现在随附的字段中。然后将此费用添加到表单上的其他费用中。

我想用 css 隐藏滞纳金复选框(但保留其随附的文本),并在特定日期/时间后在金额字段中显示 $25 滞纳金。

如果对解决方案有用,我已经有一个收集当前日期的隐藏字段。 (")

我希望我已经解释得足够好。如果被要求这样做,我会澄清。

我已经搜索了很长时间,试图找到一个无济于事的答案。希望那里的天使可以帮助我。谢谢。

【问题讨论】:

  • 你为什么不在那个特定的时间用 PHP 把它放进去?

标签: php forms validation date checkbox


【解决方案1】:

这有帮助吗?我不能 100% 确定这是否是您想要做的。

<?php

# Get a DateTime obj for the late date (christmas in this case)
$lateDate = DateTime::createFromFormat("d-m-Y", "25-12-2013", new DateTimeZone("Pacific/Auckland"));

# The date now
$now = new DateTime("now", new DateTimeZone("Pacific/Auckland"));

# Get a boolean for whether it's late or not
$isLate = ($now->getTimestamp() > $lateDate->getTimestamp());
?>

<? if ($isLate): ?>
You're late!!!
<? endif; ?>

<input type="checkbox" name="lateFee" value="25" <?=($isLate ? 'checked="checked"' : '')?> />

【讨论】:

    【解决方案2】:

    没有看到任何代码,如何:

    $today = new DateTime();
    $lateFee = null;
    $hide = null;
    if($today > $cutOffDate){
        $lateFee = 'value="25.00"';
        $hide = 'hide';
    }
    echo '<input type="number" step="any" name="lateFee" ',$lateFee,'>';
    echo '<input type = "checkbox" name="lateFeeCheckbox" class="',$hide,'">';
    

    在你的 CSS 中,你可以使用它 hide 来隐藏任何带有“hide”类的输入

    【讨论】:

      猜你喜欢
      • 2023-04-01
      • 1970-01-01
      • 2017-10-09
      • 2020-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-20
      相关资源
      最近更新 更多