【问题标题】:PHP script failing at submit: The Spam test doesn't work [closed]PHP脚本提交失败:垃圾邮件测试不起作用[关闭]
【发布时间】:2014-06-25 16:09:10
【问题描述】:

在这个 jsfiddle 中:http://jsfiddle.net/2burL/1/ 是我的 PHP 表单代码。

处理垃圾邮件变量的代码:

$human1 = mt_rand(0, 50); // random number to be written into this var
$human2 = mt_rand(0, 49); // same as $human1
$human_test = 0;  //declaration on the variable to be posted from the form
$spam_test = $human1 + $human2; // SUM the vars

测试代码:

$human_test = $_POST["human_test"];

    if (empty($_POST["human_test"]))
    {
        $humanerr = "This field is required.";
    }
    else if ($_POST["human_test"] != $spam_test)
    {
        $humanerr = "Wrong answer, try again.";
    }
    else
    {
    if ($_POST['submit'] && $test_error == 0 && $human_test == $spam_test)
    {

问题是,当所有必填字段都设置并在提交时发布时​​,“垃圾邮件测试”每次都会失败,无论答案是对还是错。

不存在语法错误。我已经测试了 $spam_test 的值,它是 SUMed togehter,但是 $_POST 到 $human_test 中并不能以某种方式工作。

我收到if 错误,表示输入的值不正确。

有人看到我的代码中的错误吗?或者有没有人有好的方法来测试错误在哪里?

感谢您的帮助。

【问题讨论】:

  • 请在此处发布您尝试过的代码。
  • 也许绘制一张简单的图片/图表来说明您希望最终结果的样子会更容易理解您的要求。

标签: php html forms


【解决方案1】:

虽然好像有不明白的地方,但是可以使用css规则 ma​​rgin: 0px auto; 用于您想要居中的 div... 查看小提琴:http://jsfiddle.net/LN5Zs/

<div style="height:150px; width:150px; background:red; margin:0px auto;">
<div style="height:150px; width:100px; background:yellow; margin:0px auto;">
    <div style="height:150px; width:80px; background:blue; margin:0px auto;">centered div</div>
</div>

【讨论】:

  • 最好避免内联样式 ;-)
  • 居中的居中。我希望所有其他都像居中左侧的 3,右侧的 3 和右侧的 3。
  • @Nick R 您显然可以将内联样式规则粘贴到您的样式表中并将它们从您的标记中删除。我只是想快速说明我的观点。 iNejc:我正在研究一个可能的解决方案……
  • 检查这个:jsfiddle.net/LN5Zs/4 这确实不是一个优雅的解决方案,但它可能会对您有所帮助。
  • @ArxontasTouSkotous 谢谢。你得到了我的要求!你这个男人。
【解决方案2】:

你能不能不使用浮动左右浮动边元素和绝对定位中心DIV,这真的取决于你想要做什么。

【讨论】:

    【解决方案3】:

    您可以使用绝对定位。将您的包装 div 设为 position:relative,将内部 div 设为 position:absolute。然后你可以随意设置它们的x和y位置,并将中心div保持在top:0; left:0;

    所以应该是:
    div 向右 - top:0; left:100%;
    div 向左 - top:0; right:100%;
    div 到顶部 - bottom:100%; left:0;
    div 到底部 - top:100%; left:0;

    这是一个有效的小提琴,提供了一个概念示例:http://jsfiddle.net/tGYze/

    【讨论】:

      猜你喜欢
      • 2016-07-11
      • 1970-01-01
      • 2017-02-09
      • 2014-02-10
      • 1970-01-01
      • 2012-11-10
      • 2011-09-18
      • 1970-01-01
      • 2011-02-22
      相关资源
      最近更新 更多