本文介绍了WordPress的形式行动提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在wordpress中具有自己的自定义表格.

have an own customized form in wordpress.

action=<?php bloginfo('template_url'); ?>/send_form.php"

在提交时,它总是发送到send_form.php但这是用于发送信息的php-我无法使用带有主题的样式....

on submit, it goes always to send_form.phpbut this php is for sending the info - and i cant style with with the theme....

在发送信息并在字段中已成功发送表单的字段中显示消息时,有没有办法停留在当前页面上?

is there a way to stay on the current page while it sends the info and print out and message in a field that the form has been sended succesfully???

有人对我有什么建议吗?

anyone have some suggestion for me?

推荐答案

答案很复杂,要做到正确一点,但这里是一种方法的要点:

The answer to this is quite involved and getting it right takes a little care, but here are the essential points of one approach:

  1. 必须将操作设置为加载当前页面,您可以通过将<form>标记中的action属性更改为:action=""
  2. 来执行此操作.
  3. 在此页面的模板文件中,检测提交表单后何时加载页面.您可以通过检查 $ _POST变量的状态来做到这一点. /li>
  4. 如果存在发布变量,请在模板文件中处理表单提交.您需要查看"send_form.php"中会发生什么,以弄清楚该怎么做.请注意不要引入安全性问题(例如,请务必使用NONCE).
  5. 重定向回同一页面以摆脱发布变量.如果您不这样做,人们将收到那些您要重新提交表单"警告消息.请参阅 PHP header()函数进行重定向,并注意这一定会发生在任何输出发送到页面之前.
  6. 使用服务器会话来显示表单提交成功".在重定向之前,为您的消息设置一个会话变量,然后在页面加载时对其进行检测,将其显示并删除,以使该消息在下次页面加载时不再显示.
  1. The action must be set to load the current page and you can do this by changing the action attribute in the <form> tag to: action=""
  2. In the template file for this page, detect when the page loads after a form submission. You can do this by checking the state of the $_POST variable.
  3. If there are post variables, process the form submission in the template file. You need to look at what happens in "send_form.php" to figure out what to do. Take care that you don't introduce security issues (e.g. be sure to use the NONCE).
  4. Redirect back to the same page to get rid of the post variables. If you don't do this people will get those "Do you want to resubmit the form" warning messages. See the PHP header() function for doing the redirect and note that this must happen before any output is sent to the page.
  5. Use server sessions to display a "Form submission successful". Set a session variable to your message before the redirect, then detect it when the page loads, display it, and remove it so the message doesn't display the next time the page loads.

这应该为您提供一个起点.

That should give you a starting point.

如果其他人有更简单的解决方案,我也很想听听.

If anyone else has a simpler solution, I'd love to hear it too.

这篇关于WordPress的形式行动提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:06