0

I am trying to make a list of anchors that will submit the value of the one clicked and redirect to another page. The form is:

<form id="searchCategory" action="test.php" method="post">
<div id="categories">
<details>
<summary>Beers</summary>
<a href="test.php" onclick="document.getElementById("title").submit();"> <input id="title" name="title">Lager </input></a>
<a href="#"> Ale</a> //would make as above
<a href="#">Pale Lager </a> // same
</details>
</form>

The top of the test.php is this:

<?php
if (!empty($_POST['submit'])){
include ("connection.php");

$title = (trim($_POST['title'])=="")?
die ("You did not enter any search criteria"):
mysql_real_escape_string($_POST['title']);

The anchor redirects me to the test.php page but the value doesn't seem to be submitted.

4

2 回答 2

1

您可以使用此处GET提交您的类别,只需GET query在您的href. 很简单,制作也很简单

<ul>
    <li><a href="test.php?cat=lager">Lager</a></li>
    <li><a href="test.php?cat=ale">Ale</a></li>
    <li><a href="test.php?cat=palelager">Pale Lager</a></li>
</ul>


//handle it in test.php page or where you want 

<?php if(isset($_GET['cat'])) { 
    echo $_GET['cat'];// do anyting with cat
}
?>
于 2013-03-24T14:31:02.150 回答
0

您的标记无效。链接不能包含输入,输入也不能包含任何内容。

如果您希望提交单击的值,则不需要链接或 JavaScript。只需使用提交按钮:

<form id="searchCategory" action="test.php" method="post">
    <fieldset>
        <legend>Beers</legend>

        <input type="submit" name="title" value="Lager">
        <input type="submit" name="title" value="Ale">
        <input type="submit" name="title" value="Pale Lager">
    </fieldset>
</form>
于 2013-03-24T13:05:09.480 回答