无法使用表单将数据插入wordpress db

时间:2015-09-05 09:47:43

标签: php wordpress insert wpdb

当我点击提交时,它不会在帖子类型中创建新帖子。它只刷新页面。下面是分配给页面的pagetemplate。

newArray

3 个答案:

答案 0 :(得分:1)

您需要在表单元素中添加name attribute

<input type="name" id="inputName" name="name" placeholder="Name">
<input type="email" id="inputEmail" name="email" placeholder="Email">
<button type="submit" name ="submit">SUBMIT</button>

答案 1 :(得分:0)

您只需要更改HTML

即可
<form method="post" action="">
<input type="text" id="inputName" placeholder="Name" name="name">
<input type="text" id="inputEmail" placeholder="Email" name="email">
<button type="submit" name="submit">SUBMIT</button>
</form>

答案 2 :(得分:-1)

<form method="post" action="">
<input type="text" id="inputName" placeholder="Name" name="username">
<input type="text" id="inputEmail" placeholder="Email" name="useremail">
<input type="submit" name="submit" value="submit">
</form>

<?php if(isset($_POST['submit'])){
global $wpdb;
$wpdb->insert( 'contacts', array('post_title'=>$_POST['username'],'email'=>$_POST['useremail']));} ?>

现在检查。我认为它运作正常。