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 组策略中的计算机配置策略无法下发
  • ¥15 机器学习简单问题解决
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写