鍍金池/ 問答/PHP  HTML/ php如何使用<a>標簽提交表單數(shù)據(jù)?

php如何使用<a>標簽提交表單數(shù)據(jù)?

后端新手在做一個筆記網(wǎng)站,剛學了半個月php基礎,目前了解到php和html交互需要借助提交<form>表單中的數(shù)據(jù),根據(jù)查閱和書上的描述,發(fā)現(xiàn)只有button和input標簽中可以通過設置name屬性提交數(shù)據(jù),有時候可能排版原因需要點擊a標簽提交表單,發(fā)現(xiàn)使用傳統(tǒng)的處理方式并不能解決,遂查詢發(fā)現(xiàn)可以借助js的方式進行跳轉(zhuǎn),但是點擊a標簽時無法像以前一樣利用if(isset($_POST['html元素name值']))判斷網(wǎng)頁端是否點擊。
想請問大家有沒有解決方案,可以讓a標簽像button和input一樣進行處理。
第一次使用segmentFault提問,先謝過大家。


原本處理方式:
html:

<form action="userdata.php" method="post">
    <div class="top">        
        <p>Green Notbook
            <p><button name="userdata">個人信息</button></p>    
        </p>        
    </div>
</form>

php:

if(isset($_POST['userdata'])){
    $userid=$_SESSION['userid'];
    $username=$_SESSION['username'];
    $data="select email,createTime from user where id='$userid'";
    $result=mysqli_query($link,$data);
?>  

查詢到解決方法:

<form id="testform" method="post">
    <div class="biji">
        <a onclick="testphp()">創(chuàng)建筆記本</a>
        <a href="#"><img src="img/3.PNG"width="35px" height="30px">新建標簽</a>        
    </div>     
</form>
function testphp(){
    var testform=document.getElementById("testform");
    testform.action="note_change_search.php";
    testform.submit();
}

這樣的方式只能跳轉(zhuǎn)到某個php文件。

回答
編輯回答
默念

不用php做判斷,而用js做判斷

2018年8月8日 07:26
編輯回答
不二心
<a href="javascript:document:search_form.submit();">提交</a>

search_from 表單ID

2017年4月26日 11:06