doucanrui1735 2013-07-24 17:11
浏览 69
已采纳

用于wordpress的php表单处理

I am adding a form to my wordpress with a custom php page template

Below is my wordpress page template php code:

<?php
/*
Template Name: Form
*/
?>

<?php get_header(); ?>

<div id="content">

    <h1 class="page-title"><?php the_title(); ?></h1>

    <div class="entry">

        Welcome <?php echo $_POST["fname"]; ?>!<br>
You are <?php echo $_POST["age"]; ?> years old.

    </div> <!--end .entry-->

</div> <!--end #content-->

<?php get_sidebar(); ?>

<?php get_footer(); ?>

And I am including the following code from my page which shows the form

<form action="http://127.0.0.1:4001/wordpress/script" method="post">
Name: <input type="text" name="fname">
Age: <input type="text" name="age">
<input type="submit">
</form>

This will show the form data in a new page instead of showing the result on the same page. How can I show the result on same page?

I would like to have something like this:

enter image description here

  • 写回答

4条回答 默认 最新

  • dongyan3018 2013-07-24 17:14
    关注

    Remove the action attribute from your form:

    <form method="post">
    

    UPDATE

    Now, to keep data on your fields after form submit, just print them on its respective fields:

    Name: <input type="text" name="fname" value="<?php if (isset($_POST["fname"])) echo $_POST["fname"]; ?>" />
    Age: <input type="text" name="age" value="<?php if (isset($_POST["age"])) echo $_POST["age"]; ?>" />
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝