Forum Moderators: coopster
for example a create a form that is to be process by the same page and I would like to make sure that once the data was input from the form, the page itself would refresh to load again since the data would appear on the page and even save the data into a cookie.
Thanks.
ie
<?
if ($HTTP_POST_VARS["submitted"] == "yes"){
echo "<meta http-equiv='refresh' content='0;URL=thepage.php'>";
}
?>
Then in the form:
<input type="hidden" name="submitted" value="yes">
That should do it, although I haven't tested it.
ps, please ignore any typos - I'm not good before 9am
would it not work to insert a refresh tag in the head almost as if it where an html document
It is an html document that gets sent to the UA.
I donīt really understand why you want to refresh the document containing the form. If you refresh the page before the user submits the form you wonīt get any data and the user will be confused.
There is no need to refresh the page after it is submitted to display the data the user submitted again or save them in a cookie. Just send a cookie in the header of your HTTP reply to the userīs POSTed request. To display the data the user entered just send them in the html document contained in the body of that same reply.
Your form processing would then look like this.
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// check supplied data
if (count($errors) > 0) {
// process data
setcookie('name', $data);
// echo the data user submitted
exit;
} else {
// clean up
}
}
// display form Andreas
I created a form that would accept data for the font size; small, medium and large.
the form would be processed by the same page. and would send a data or create a cookie with the data of the font size.
then then same page would also use or get the data from the cookie to refresh the page and change it font size.
I have created one using meta refresh tag and it is working.
how about a sort or referrer page that would receive the data from the form the refer it back to the current page?
any input would be very much appreciated.
thanks. :)
In essence:
//adminpage.php
...
<HEAD>
{
check for stuff if we need to mess up the font or something, spit CSS code accordingly
See if isset($flag) and other form fields are not empty($formfield) or strlen($otherformfield)<1 stuff!}
</HEAD>
...
switch ($flag)
{
case action1: { Do stuff & set flag if need to}
case action2: { Do stuff & set flag if need to}
case action2: { Do stuff & set flag if need to}
default : { Do stuff & set flag if need to (this is what we will do the first time, but not necessarily every time}
}
This is what we will do every time, irrelevant of the flag.
<form action="adminpage.php?flag=$appropriate_action" method="POST">
can set the flag here too by multiple
<input type=submit value=flag1 etc...> or
<input ... name=fontsize (we can use it in the header when submitted)></form> The form would pass all the information that you need to itself. It will pass both the POST information from the
<form> AND the GET information you faked in the <form> URL. Combining POST & fake-GET works perfectly in IE, Mozilla and Opera for me. Make sure you do not run over the variable names between the POST and GET, i.e. name them the same. Also make sure you use the following format:
METHOD="http://www.x.net?field1=value1&field2=value2&field3=value3" Notice how the first field1 is separated by a? (question mark), but all following fields are separated from each other by an & (ampersand).
Let me know if you need more detailed code.
if (count($errors) > 0) { should read:
if (count($errors) == 0) { You would want to process the form data only if there were no errors in it ;)
Andreas
for example the page where you try to change the font size (from a form) is: www.site.com?id=2&p=1
how can i make it sure that when it refresh the page it would still refer to that address (www.site.com/test/test.php?id=2&p=1) and not on the mother page (www.site.com/test/test.php)?
in the headers part "url=", what i use is $php_self. anything I should change?
thanks for your input on this. they are all very helpful. :)
it tried that but i experience problem adding the $_SERVER['QUERY_STRING'] in the header() part with the $PHP_SELF.
anyway, the workaround i did was to put them (PHP_SELF and QUERY_STRING) in the a hidden input in the form, $_POST['hiddeninput'] and have it put into the header url and it is working.
my question is ....
is there any security issue when i doing that?
Thanks again.
[w3.org...]
anyway another lesson learned and i do the http redirect to refresh my page. :)
hope this helps.
Use standard redirects: don't break the back button!Don't use "refresh" to redirect
If you want [example.org...] to actually display what's at [example.org...] do notuse "refresh" techniques like :<META HTTP-EQUIV=REFRESH CONTENT="1; URL=http://machine/doc3.html">.Why? because it breaks the "back" button. If the user presses the "back" button, the refresh works, and the user bounces forward. The user will most likely get very annoyed, and close the window. That's not what you want, is it?