On Thu, 2002-02-14 at 11:09, James Taylor wrote:
> Can someone recommend a better method for doing something like the following?
> All of my programs are written like this, but it's really poor form
> considering I'm not predeclaring my variables, etc. Only thing I can really
> think of is to assign a value in the form a number like 1 or something, then
> do a if $value == 1 {do something} but that seems kinda hokey. Here's an
> example of something I'd do:
>
>
> <HTML><BODY>
>
> <?
>
> if ($submitdata) {
First, don't use globals. Use $_REQUEST, $_POST, or $_GET
($HTTP_POST_VARS or $HTTP_GET_VARS in versions of PHP [prior to
4.1.0). globals clutter things up, encourage tight binding, and
are easily spoofed by malicious ne'er-do-wells. (As opposed, I
suppose, to benevolent ne'er-do-wells?)
> dosomething;
> exit;
> }
Move the aove handler bit into a function or class and return
a value to indicate whether it succeeded or failed. If you just
exit() where you are, you'll wind up with a half-written page
being sent to the user. Not pretty.
> echo "<form name=\"form\" action=\"$PHP_SELF?\">\n";
> echo " <input type=\"text\" name=\"data\">\n";
> echo " <input type=\"submit\" name=\"submitdata\" value=\" Submit \">\n";
> echo "</form>\n</body>\n</html>";
>
> ?>
You might want to put the form in a heredoc or break out of PHP mode
entirely here:
echo <<<EOT
<form name="form" action="{$_SERVER['PHP_SELF']}">
<input type="text" name="data">
<input type="submit" name="submitdata" value=" Submit">
</form>
</body>
</html>
EOT;
Torben
--
Torben Wilson <[EMAIL PROTECTED]>
http://www.thebuttlesschaps.com
http://www.hybrid17.com
http://www.inflatableeye.com
+1.604.709.0506
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php