2013-03-24 74 views
0

我想提出一個錨點列表,將提交一個點擊並重定向到另一個頁面的值。形式是:使用錨點列表提交表單並重定向

<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> 

的test.php的的頂部是這樣的:

<?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']); 

錨重定向我的test.php的頁面,但價值似乎並沒有提交。

+0

你有引用的問題! – adeneo 2013-03-24 12:59:13

回答

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> 
+0

謝謝你的回覆。我避免這樣做,因爲我不能CSS這些按鈕。 – anaxin 2013-03-24 13:16:18

+0

大多數瀏覽器都非常靈活地應用CSS來提交按鈕。 – Quentin 2013-03-24 13:18:34

+0

對不起,忽略該評論。意識到我可以讓它看起來像鏈接。感謝您的迅速幫助。 – anaxin 2013-03-24 13:28:18

1

可以使用這裏GET提交您的類別,只是做一個GET queryhref後。 這很容易,而且很簡單

<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 
} 
?>