【问题标题】:$_POST returns empty on form submit in wordpress$_POST 在 wordpress 中提交表单时返回空
【发布时间】:2013-03-26 12:17:23
【问题描述】:

我有一个表格:

<form action="<?php echo the_permalink(); ?>" method="POST">
    <input type="text" name="name" value="" placeholder="Your First and Last Name *" />
    <?php echo $firstnameError; ?>
    <input type="text" name="email" value="" placeholder="Yoyr Email" />
    <?php echo $emailError; ?>
    <br>
    <input type="text" name="company" value="" placeholder="Your Company Name" />
    <input type="text" name="phone" value="" placeholder="Your Phone number" />
    <textarea name="project" rows="4" cols="50" placeholder="Describe the scope of work and the most important features of the project *'"></textarea>
    <?php echo $addressError; ?>
    <br>
    <input type="radio" name="budget" value="1500" />
    <input type="radio" name="budget" value="2500" />
    <input type="radio" name="budget" value="5000" />
    <input type="radio" name="budget" value="10000" />
    <input type="radio" name="budget" value="100001" />
    <input type="radio" name="budget" value="not sure" />
    <input type="hidden" name="submit" value="1" />
    <input type="submit" value="SUbmit" />
</form>

它对同一页面进行操作,但是当我执行print_r($_POST); 时,它不会打印任何内容,即$_POST 中没有任何值。

这可能是什么原因?我研究了一些关于 SO 的问题,但没有一个给出我想要的答案。

【问题讨论】:

  • 你只是忘记了action属性中的i('action'而不是acton
  • @JoDev 这是一个错字
  • Stackoverflow 非官方规则 #1,不要输入问题。总是,我总是重复复制/粘贴

标签: php wordpress forms post


【解决方案1】:

如果您将名称作为 Post 值传递,wordpress DOSNT 就像这样!

改变这个

<input type="text" name="name" value="" placeholder="Your First and Last Name *" />

<input type="text" name="thename" value="" placeholder="Your First and Last Name *" />

name 更改为 thename,保证可以正常工作! ;)

【讨论】:

  • excellent ;) wordpress 不喜欢传递的名称值,使用您自己的命名约定总是好的。米
  • 就我而言,这是解决方案,但我没有使用“名称”,而是使用“id”作为标识符。
【解决方案2】:
<form action="<?php the_permalink(); ?>" method="POST">

您无需回显the_permalink()

这对我有用:

<?php print_r($_POST);?>
<form action="" method="POST">
  <input type="text" name="name" value="" placeholder="Your First and Last Name *" /><?php echo $firstnameError; ?><input type="text" name="email" value="" placeholder="Yoyr Email"/><?php echo $emailError; ?><br>
  <input type="text" name="company" value="" placeholder="Your Company Name"/><input type="text" name="phone" value="" placeholder="Your Phone number"/>
  <textarea name="project" rows="4" cols="50"placeholder="Describe the scope of work and the most important features of the project *'"></textarea><?php echo $addressError; ?><br>
  <input type="radio" name="budget" value="1500" /><input type="radio" name="budget" value="2500" /><input type="radio" name="budget" value="5000" /><input type="radio" name="budget" value="10000" /><input type="radio" name="budget" value="100001" /><input type="radio" name="budget" value="not sure" />
  <input type="hidden" name="submit"value="1"/>
  <input type="submit" value="SUbmit" />
</form>

【讨论】:

  • 还是一样..$_POST 没有结果
  • 将输入变量的名称更改为独特的名称。它有时会与 WordPress 的保留名称发生冲突
  • 我不明白为什么,但它不适合我!!我知道它的基本功能,但无法让它发挥作用!
  • 您是否更改了name 属性?
【解决方案3】:

改变这个

acton="<?php echo the_permalink(); ?>"

action="<?php echo the_permalink(); ?>"

【讨论】:

  • 那是一个错字...实际上是表单中的操作
  • 你不回显the_permalink()
【解决方案4】:

我在我的项目中发现了同样的问题,解决方案在 $_POST 中,也许您在代码中使用小写字母,将其更改为大写字母。 将 $_post 更改为 $_POST !

【讨论】:

    【解决方案5】:

    解决方案:

    由于请求问题,在wordpress网站中代替

    <form action="http://example.com/">...
    

    你可能需要指向.php文件..例子:

    <form action="http://example.com/index.php">...  
    


    //////ps echo 使用 the_permalink() 自动完成 [同样是:echo get_permalink()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-01
      相关资源
      最近更新 更多