开发者

Who sent you?

I have a series of input forms, all of them take a different form action. Each of those validates input. If ok, they go to different success pages. If fail, I want the form action/validation pages to set $_SESSION['error_messages'] and go to a common page whi开发者_高级运维ch displays the errors and has a "resubmit" button.

Question ... how to get error form the resubmit button back to one of many possible input forms?


Edit: I don't see how $_SERVER['HTTP_REFERER'] is going to work. Again: form --> validation --> error_page

So, I guess that validation has to set a session variable from $_SERVER['HTTP_REFERER']


USing HTTP_REFERER is an option, but possibly not the most viable one, as the referrer header is easily spoofable (and not all the browsers will send it). This may or may not interfere with your process.

The easiest thing to do, as you are already setting error messages in $_SESSION is to also add a $_SESSION['redirect_url'] value.


Using $_SERVER['HTTP_REFERER'].

But, as per http://php.net/manual/en/reserved.variables.server.php

The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

So, like Neal Donnan has suggested, passing the module_name in a hidden field and then resubmitting to http://project/'.$_POST['module_name'] would be best


You can use the HTTP_REFERER header, but this is not always reliable as the browser needs to set this.

A more reliable way would be to set a hidden field in each form with the url to redirect back to.


I'm assuming that you're using the same script, if not please post your code:

Input page:

<?php
/* this is the form page header */

/* parsing & filtering input */

if( my_form_is_valid($input_data) )
   give_the_answer();
else
   header('Location:' . $_POST['request_uri'] . '&status=error');  //make sure that's the first output

/* follow the DOM */
?>

<form id="myform">
   <!-- some fields -->
   <input type="hidden" name="request_uri" id="request_uri" value=<?=$_SERVER['REQUEST_URI']; ?>" />
</form>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜