【问题标题】:PHP form design help [duplicate]PHP表单设计帮助[重复]
【发布时间】:2011-11-22 10:38:34
【问题描述】:

可能重复:
Robust, Mature HTML Parser for PHP
Help coding an HTML Form

这是我想到的设计模型 - http://i.imgur.com/ujiLb.jpg

在每组选项中,只有一个必须被选中,并且根据复选框的组合,“提交”按钮会指向网页。

这两个功能将是

价格(请选择一项)

1-99 100-249 250-499

制造商(请选择一个)

A B C

[提交按钮]

我能理解的肯定是错误的编码是:

//search page
...
<form action='search.php' method='post'>
<input type=radio name=product value='a'>A?</input>
<input type=radio name=product value='b'>B?</input>
<input type=radio name=product value='c'>C?</input>
<br>
<input type=radio name=price value='5'>5-10?</input>
<input type=radio name=price value='10'>11-15?</input>
<input type=radio name=price value='other'>15+?</input>
... </form>

在 search.php 中,类似 ...

<?php
$product = $_POST("product");
$price = $_POST("price");
...
if (($product == "A") && ($price == "5")) {
 Location("a-5-10.html"); // Products matching A, price 5-10 etc
elseif (($product == "B") && ($price == "5")) {
 Location("b-5-10.html"); //Products matching b, price 5-10 etc
....
endif
?>

根据 OP 的 cmets 进行编辑, 请求没有被重定向到“b-5-10.html”或“a-5-10.html”等。

【问题讨论】:

    标签: php html forms


    【解决方案1】:

    $_POST是数组,不是函数,你要$_POST['product'];

    $product = $_POST["product"]; //note [ and ] instead of ( and )
    $price = $_POST["price"];
    

    另外Location 不是我知道的功能,正如@erisco 指出的你需要使用header

    if (($product == "A") && ($price == "5")) {
      header("Location: a-5-10.html"); // Products matching A, price 5-10 etc
    } //also note the closing brace
    elseif (($product == "B") && ($price == "5")) 
    { 
      header("Location: b-5-10.html"); //Products matching b, price 5-10 etc
    } //again, closing brace, not "endif"
    

    【讨论】:

    • 谢谢这真的让我明白了很多。对于搜索页面本身,您能告诉我如何编写提交按钮请求的代码吗?
    • 您只需要在表单中添加一个 并添加一个“搜索”按钮
    • 谢谢!当我在 search.php 上输入以下内容并单击搜索时,它只是向我显示 search.php &lt;?php $product = $_POST["product"]; $price = $_POST["price"]; if (($product == "a") &amp;&amp; ($price == "5")) { header("Location: a-5-10.html"); // Products matching A, price 5-10 etc } //also note the closing brace elseif (($product == "B") &amp;&amp; ($price == "5")) { header("Location: b-5-10.html"); //Products matching b, price 5-10 etc } //again, closing brace, not "endif" ?&gt; 上的代码
    • 这就是我的搜索页面的样子 `
      A? input> B? C?
      5-10? 11-15? 15+?
      `
    • 如果它显示您的代码,您需要确保 php 已安装并在您的服务器上正常工作
    猜你喜欢
    • 1970-01-01
    • 2011-10-15
    • 1970-01-01
    • 2011-04-21
    • 2011-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-01
    相关资源
    最近更新 更多