2013-12-17 38 views
0
<?php 
echo $_POST['textvalue']; 
echo $_post['radiovalue']; 

?> 
<div id="hidethis"> 
<form method="POST" action=""> 
<label>Tekst Value</label> 
<input type="text" name="textvalue"> 
<label>Radio Value</label> 
<input type="radio" name="radiovalue" value="autogivevalue"> 
<input type="submit" id="submit" name="submit" value="submit"> 
</div> 

http://jsfiddle.net/Bjk89/2/這裏是它的jQuery。提交時隱藏div並將值發送給PHP

我試圖做的是在點擊submit時隱藏<div id="hidethis">

我知道我可以做另一個網頁,我能接受的值沒有<form>部分,但我想提出兩個在一個頁面中,使<div id="hidethis">submit後隱藏。

所以我能夠得到echo $_POST['textvalue'];echo $_post['radiovalue'];作爲結果

結果一定是這樣

文本//這是希望的值輸入到Tekst價值

autogivevalue//這是單選按鈕的值

----- INVISIBLE -----

<form is hidden because we set it in jQuery so> 
</form> 

回答

3

試試這個。這裏不需要使用jQuery。

<?php 
if($_POST) { 
    echo $_POST['textvalue']; 
    echo $_post['radiovalue']; 
} else { 
?> 
    <form method="POST" action=""> 
     <label>Tekst Value</label> 
     <input type="text" name="textvalue"> 
     <label>Radio Value</label> 
     <input type="radio" name="radiovalue" value="autogivevalue"> 
     <input type="submit" id="submit" name="submit" value="submit"> 
    </form> 
<?php 
} 
?> 
+0

你甚至可以使用'<形式方法= 「POST」 行動= 「」 的onsubmit = 「$( '#hidethis')隱藏()」>'來隱藏它甚至有點更快;-) – Farce

+0

但如果表單提交,頁面重新加載,然後再顯示div,不是? – Floris

+0

當然,我只是想和你的代碼結合起來:-) – Farce

0

嘗試在您的jquery代碼中添加'#'。您的版本沒有提交旁邊的#號。此外,您的表單在這裏和JSFiddle代碼中缺少結束標記。

試試這個:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 

<script> 
$(document).ready(function() { 
    $('#submit').click(function() { 
     $('form').submit(); 
     $('#hidethis').hide(); 
    }); 
}); 
</script> 
    <form method='post' id="hidethis" name='form'> 
     <input type="text" name="textvalue"> 
     <input type="radio" name="radiovalue" value="1"> 
     <input type="button" id="submit" name="submit" value="submit"> 
    </form>