簡體   English   中英

Wordpress自定義表格到數據庫

[英]wordpress custom form to database

我正在嘗試在wordpress上創建自定義提交表單,我正在使用二十四主題中的wp頁面模板,並將我的代碼放在

<div id="content" class="site-content" role="main">

$wpdb->insert('wp_table',array (
                    'db_column' => $inputtext,
                    )
                );

它可以工作,但是每次頁面加載時,它也會將空白數據提交到我的wp_table中。 如何避免呢? 我只想使用提交按鈕輸入數據。

您可以避免通過使用PHP中的isset將空白數據提交到wordpress表中

if(!empty($_POST['streamname'])) {

// the code
}

看到一個..希望這是有幫助的

if( count($_POST) ){
         $wpdb->insert('wp_table',array (
                'db_column' => $inputtext,
                )
            );

}

提交數據之前,必須確保它不為空。 這是正確的方法:

if(!empty($_POST['datakey'])) {
    $wpdb->insert('wp_table',array (
                'db_column' => $inputtext,
                )
            );
}

此代碼段在Wordpress插件或主題中很常見。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM