PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I've just started learning to program in PHP. Top stuff! Well.. I was going through the book and I was getting rather fed up of having to POST my FORM data to a seperate PHP document for processing. So I came up with this handy little work around.
<? // RETURN TO SENDER
// --------------------------------------------------------------------------------------------------
// Using this method, you do not need to create seperate .HTML and .PHP files.
// You can serve the HTML FORM and process the PHP output in one simple IF statement!
//
// The PHP parser starts by checking weather there is anything in the POSTed [location] variable.
// If there's nothing in there, it must be the first time the PHP script has run... in which case...
// ECHO the HTML FORM. When the SUBMIT button is pressed, the FORM sends the data back to the same
// PHP document. Genius!
//
// Hence - "RETURN TO SENDER"
//
// Once the PHP has been restarted, it now carries with it... the POST variable [location].
// Because this variable is now filled with data, the script takes the opposite route and
// processes the data.
//
// Budda-bing!
//
// (HINT: Be sure to escape and PHP charaters in the ECHO block!)
// EG: echo "\"Hello World!\""
if ($_POST[location] == ""){ // Get the POSTed variable (if one has been posted yet).
echo // If the [location] variable is NULL, ECHO the HTML form.
"<html><head><title>Redirection Menu</title></head><body>
<FORM METHOD=\"post\" ACTION=\"redirect.php\">
<p>Send me to:
<SELECT name=\"location\">
<OPTION value=\"http://www.doctorfilter.com.com/\">Doctor Filter's Personal Website</OPTION>
<OPTION value=\"http://www.somethingfruitful.com/\">Som ... om</OPTION>
<OPTION value=\"http://www.totos.org/\">TOTOS - Child Advocasy Group</OPTION>
<OPTION value=\"http://www.christianvideos.co.uk/\">NPN Videos</OPTION>
</SELECT>
<p><INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Go!\"></p>
</FORM>
</body>
</html>"; // Finished ECHOing the HTML FORM.
} else { // If the value of [location] is not NULL...
header("Location:$_POST[location]"); // Print the new HEADER LOCATION.
exit;
}
// RETURN TO SENDER
// --------------------------------------------------------------------------------------------------
// Using this method, you do not need to create seperate .HTML and .PHP files.
// You can serve the HTML FORM and process the PHP output in one simple IF statement!
//
// The PHP parser starts by checking weather there is anything in the POSTed [location] variable.
// If there's nothing in there, it must be the first time the PHP script has run... in which case...
// ECHO the HTML FORM. When the SUBMIT button is pressed, the FORM sends the data back to the same
// PHP document. Genius!
//
// Hence - "RETURN TO SENDER"
//
// Once the PHP has been restarted, it now carries with it... the POST variable [location].
// Because this variable is now filled with data, the script takes the opposite route and
// processes the data.
//
// Budda-bing!
//
// (HINT: Be sure to escape and PHP charaters in the ECHO block!)
// EG: echo "\"Hello World!\""
if ($_POST[location] == ""){ // Get the POSTed variable (if one has been posted yet).
echo // If the [location] variable is NULL, ECHO the HTML form.
"<html><head><title>Redirection Menu</title></head><body>
<FORM METHOD=\"post\" ACTION=\"redirect.php\">
<p>Send me to:
<SELECT name=\"location\">
<OPTION value=\"http://www.doctorfilter.com.com/\">Doctor Filter's Personal Website</OPTION>
<OPTION value=\"http://www.somethingfruitful.com/\">SomethingFruitful.com</OPTION>
<OPTION value=\"http://www.totos.org/\">TOTOS - Child Advocasy Group</OPTION>
<OPTION value=\"http://www.christianvideos.co.uk/\">NPN Videos</OPTION>
</SELECT>
<p><INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Go!\"></p>
</FORM>
</body>
</html>"; // Finished ECHOing the HTML FORM.
} else { // If the value of [location] is not NULL...
header("Location:$_POST[location]"); // Print the new HEADER LOCATION.
exit;
}
// A Script by >>>---[F1LT3R]---|>
<?php
echo <<<something
your content here
something;
?>
Rules:
First line (with the echo command) must end after the "something" identifier (which can be any alphanumeric string).
The last line must be the identifier followed by a semicolon, and nothing else.