[thelist] php form
DESCHAMPS Stéphane DvSI/SICoR
stephane.deschamps at francetelecom.com
Fri Nov 22 10:57:01 CST 2002
> -----Message d'origine-----
> De : thelist-admin at lists.evolt.org
> [mailto:thelist-admin at lists.evolt.org]De la part de Tom Dell'Aringa
> 1 - When writing out code to your page, is it best to:
>
> a) echo("foo");
> b) print "foo";
I seem to prefer echo(), someone explianed the reason to me a long time ago and I found it convincing enough to stop using print. I guess it's got something to do with future deprecation and coherence of code (all other functions being ()'d).
[interspersing HTML]
> I seem to find that much easier when there is a lot of stuff instead
> of worrying about packing it all into one string with quote issues.
It depends on the volume of code I'd have to anti-slash. Usually for one line I put it all inside echos. Especially when dealing with PHP objects.
> 2 - What is the difference between <?php and simply <? - i'd prefer
> not to type php all the time if I don't have to.
Convention. cf. your php.ini, somewhere it is specified that you an omit it. If it works on your server then omit <?php for <?
> 3 - question about isset() - will a form field that has no value
> (i.e. <input type='text' value=''>) be considered set or not? I
> seemed to have some trouble with that.
I prefer to double-check the variable like so:
if(!isset($foo) || $foo=="") { do something; }
For me when you submit, $HTTP_POST_VARS['foo'] has an empty value, so it may be set...
For example test this in a page (say example.php):
if(!isset($HTTP_GET_VARS['foo'])) {
echo "foo is not set";
} else {
echo "foo is set";
}
It will tell you foo is not set.
But example.php?foo= will tell you $foo is set.
I should be tested for POST variables, but usually I double-test for every variable.
More information about the thelist
mailing list