PHP - 表单,发布到同一页面,错误处理,防止重新提交

I have come across quite the problem when making my own framework. I have found some other questions that come close to what I'm asking, but not quite.

This is what I am attempting:

  • Page has a form with method post and submits to itself (same page).
  • When you submit, the input is validated appropriate messages / errors are displayed.

It seems simple, but I am trying to:

  • Avoid form resubmission that comes with using post. This wouldn't be a problem if I also wasn't trying to...
  • Avoid having duplication or more code than needed. Redirection adds an extra action where I would need to check the input twice (once on the submit page for validation and once on the redirected page for messages/ errors).
  • Avoid using query strings, cookies or sessions. Which makes the solution of posting to another page and then redirecting while still having message handling impossible (as far as I know).
  • Avoid relying on AJAX since JS can be disabled.

Am I asking too much or is there a way to do this? Is there something I would need to compromise on to achieve this? If not, then I guess I will go with sessions and redirection.

i am not sure i understood well, do you need to process $_POST on the same page, which holds the form and avoid re-sending the data?

if so, u need to reload page, without POST after proceeding your form ... i.e.

 if(isset($_POST["YOUR_FORM_FIELD"])){
   header("Location: ".$_SERVER["HTTP_REFERER"]);
   exit();
 }

BUT - reloading is in conflict with your request to not use _SESSION, or _GET nad send a message to be displayed. i did not find a way how to pass a variable through HTTP headers - which seems to me like the only way ...

anyway i do recommend to consider using _SESSION ....