wordpress form action submit

前端 未结 2 825
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-01 02:44

have an own customized form in wordpress.

action=/send_form.php\"

on submit, it goes always to se

2条回答
  •  忘掉有多难
    2021-01-01 03:07

    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. The action must be set to load the current page and you can do this by changing the action attribute in the
      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.

提交回复
热议问题