Re: php form and ssi



Henrik Carlqvist <Henrik.Carlqvist@xxxxxxxxxxxx> wrote:

Finally, the solution:

the_form.php:
-8<-------------------------------------------
<?php

/* This if and else is to pass form data from .shtml to .php */
if(isset($_POST["my_parent"]))
{
$my_parent = $_POST["my_parent"];
unset($_POST["my_parent"]);
virtual($my_parent);
return;
}
else if(!isset($my_parent))
{
$my_parent = $_SERVER["REQUEST_URI"];
}


/* Here we take care of the data from the form */
if(isset($_POST["The_Button"]))
{
printf("The button was pressed\n");
}

/* This is the form */
printf("<form method=\"post\" action=\"%s\">\n", $_SERVER["PHP_SELF"]);
printf("<input type=\"hidden\" name=\"my_parent\" value=\"%s\">\n",
$my_parent);

?>

<input type="Submit" name="The_Button" value="Press me">
</form>
-8<-------------------------------------------

the_page.shtml:
-8<-------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>SSI test</title>
</head>

<body>
<h1>SSI test</h1>
This page contains all the goodies we want to display close to the form.<hr>

<!--#include virtual="the_form.php"-->

</body>
</html>
-8<-------------------------------------------

The above works without any endless recursion problem both when the php
file is called directly in the browser and when called from a .shtml file.
The only thing that might seem a little odd for a user is that once any
data in a form has been submitted the URL in the browser will point to the
..php file even though the contents of the .shtml file is shown. If the
visitor then would click in the browsers URL field and press enter the php
output would be shown without the .shtml contents. I don't consider that
to be a big problem.

Thanks to Alvaro who helped me find this solution and also thanks to Jerry
for sharing his experience.

regards Henrik
--
The address in the header is only to prevent spam. My real address is:
hc3(at)poolhem.se Examples of addresses which go to spammers:
root@localhost postmaster@localhost

.


Quantcast