Re: good practice
| From: | Julio Nobrega Trabalhando | Date: | Thu, 14 Feb 2002 20:31:45 +0000 |
| Subject: | Re: good practice | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-84800@lists.php.net to get a copy of this message | ||
Well, for instance. I don't like forms that submit to the same page where
it is located. Separating them helps to maintain the code (usually). I don't
like html inside <?php so 99% of the times I escape with ?>.
Btw, you should start with <?php and not <?.
Your input is missing the /, newer versions of HTML (or XHTML) recommend
to finish tags that explicitily don't have a finishing term, with /. So
it's:
<input type="text" name="data" />
And if $submitdata is expected to come from a form, check it:
if ($_SERVER['HTTP_REFERER'] == 'somepage.php') {
if (isset($_POST['submitdata'])) {
dosomething;
}
}
I also don't like to exit(); programs, but I don't know your whole
situation, so your mileage may vary.... And sometimes use a } else { on
expected values with some nasty error messages (just in case someone is
trying to 'crack' your app).
--
Julio Nobrega.
Um dia eu chego lá:
http://sourceforge.net/projects/toca
Ajudei? Salvei? Que tal um presentinho?
http://www.submarino.com.br/wishlistclient.asp?wlid=664176742884
"James Taylor" <jtx@nestllc.com> wrote in message
news:20020214191815.472A320CFDF@shell.hatesville.com...
> 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) {
> dosomething;
> exit;
> }
>
> 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>";
>
> ?>