doulun1666 2016-10-27 07:22
浏览 35
已采纳

数据插入数据库后,如何在wordpress中使用php重定向到帖子

I am new to wordpress.I have a program in which form submission and data insertion are in the same page.

What i want is when data is inserted into the database a "thank you" post page will generate.

I have already used the header function for redirecting but it is not working.Please see the program below.

Do i placed the else statement wrongly?

Along with this i want to know where do i will set the form validation function in this program?

Please help me.

Here is the program

<!DOCTYPE html>
<html>
<style>
input[type=text], select {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}

input[type=submit] {
    width: 100%;
    background-color: #4CAF50;
    color: white;
    padding: 14px 20px;
    margin: 8px 0;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

input[type=submit]:hover {
    background-color: #45a049;
}

div {
    border-radius: 5px;
    background-color: #f2f2f2;
    padding: 20px;
}
</style>
<body>

<h3>Form Name</h3>
[insert_php] if (!empty($_POST))


$cname=$_POST['cname'];
$pname=$_POST['pname'];
$webtype=$_POST['webtype'];
$contact=$_POST['contact'];
$email=$_POST['email'];
$address=$_POST['address'];
$pappdate=$_POST['pappdate'];
global $wpdb;

$wpdb->insert( 
    'tab_m_webdesign', 
    array( 
   'cname' => $cname,
   'pname' => $pname,
   'webtype' => $webtype,
   'contact' => $contact,
   'email' => $email,
   'address' => $address,
   'pappdate' => $pappdate
        ), 
    array( 
        '%s', 
        '%s', 
                '%s', 
'%s', 
'%s', 
'%s', 
'%s' 
    ) 
);

header("Location: http://example.com/myOtherpost");



[/insert_php]
<div>
[insert_php] else [/insert_php]
  <form action="" method="post" name="webForm">
    <label for="cname">Company/Institute Name</label>
    <input type="text" id="cname" name="cname">

    <label for="pname">Your Name</label>
    <input type="text" id="pname" name="pname">

    <label for="webtype">Type of Website</label>
    <select id="webtype" name="webtype">
      <option value="Personal(Static Pages)">Personal(Static Pages)</option>
      <option value="Personal(Dynamic Page)">Personal(Dynamic Page)</option>
      <option value="Commercial(Static Pages)">Commercial(Static Pages)</option>
      <option value="Commercial(Dynamic Page)">Commercial(Dynamic Page)</option>
      <option value="Online Shopping Site">Online Shopping Site</option>
      <option value="Educational Site">Educational Site</option>
      <option value="Other">Other</option>
    </select>
    <label for="contact">Contact No.</label>
    <input type="text" id="contact" name="contact">
    <label for="email">Email ID</label>
    <input type="text" id="email" name="email">
    <label for="address">Address</label>
    <input type="text" id="address" name="address">
    <label for="pappdate">Preferred Appointment Date</label>
    <input type="date" name="pappdate">

    <input type="submit" value="Submit">
  </form>
[insert_php] endif; [/insert_php]
</div>

</body>
</html>
  • 写回答

1条回答 默认 最新

  • dousi1970 2016-10-27 07:50
    关注

    Header function must be called before any output on the page. You should place you php insert code before html tag.

    Another way is add ob_start() on top of page.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘