douqian2524 2014-11-30 23:21
浏览 448
已采纳

WordPress自定义页面提交表单

I'm trying to write a simple script to write some data to mysql then read it. My code is working without a problem alone but I'm trying to use it inside a WordPress page, this is the point problem starts.

I have created a template file for WordPress, and using this template to create the page. Page shows up without a problem but whenever I try to submit the form inside it (my custom php form) it forwards me to index.php .

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<span>Enter Your Code : </span><br/>
<input type="text" name="sha256"><br/>
<p align = right><input type="submit" name="shaSubmit" value="Submit" /></p>
</form>

this is my form (inside custom php), and as you can see it posts the data to itself. At the the start of my custom php code I have

if(isset($_POST['Submit']))

But it doesn't matter, as soon as I click on button, it forward me to domain.com/index.php

Btw, this custom php is on a page with such url domain.com/custompage/

How can make this form work ?

ps. Code above is for reading from mysql.

  • 写回答

2条回答 默认 最新

  • dongyan1899 2014-12-01 07:26
    关注

    You need to change 2 things.

    (1)make action=""

    don't need to use action=" echo htmlspecialchars($_SERVER["PHP_SELF"])"

    (2)if(isset($_POST['shaSubmit'])){

    the code ....

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题