NewbieNotes is a little series of tips for people who are new to PHP to give them a few handy tips that the more experienced of us use often
Tip #1
The global variable $PHP_SELF holds the name of the script that's currently running.
You'll often define a form as something like...
<form action="index.php" method="post">
This is usually because you want to check that what the user just entered was valid, to allow for repeated operations until you opt out etc. You'll end up doing it quite a bit.
All very good and proper, but what happens if you rename the file? It's quite easy to forget to remember to update the internal links to your own page?
Shiraz Esat wrote :1075
It is also possible to have <form action="" ...>
to post back to the page you`re on (no PHP required!).
I`m not sure, though, which browsers support this shortcut.
Ade Morgan wrote :1076
I don`t think you even need the `action` attribute to post to the same page, all you need is:
<form method="post">
Boaz Yahav wrote :1077
The question is : will it work for all clients?
Simon Booth wrote :1078
Actually the point is that you _should_ use attributes even if they`re optional. It`s good style and if there are any quirks with a browser you`re guaranteed your code will work.
For example you don`t _need_ a closing </option> tag in a select list but it`s better to have one than not to have one.
The other thing is that you can`t guarantee how JavaScript will work if an attribute is missing and it`s often desirable to alter the value of a given attribute.
Omitting an attribute just cos it works is just lazy.
ezone ezone wrote :1079
Don`t forget to produce well formated code... it pays in the future :-)
Simon Booth wrote :1080
The above comment is extremely true
Indentation of things like forms etc is also a very good idea - it makes it much easier to find the buit you wanna change if you ever need to do so
The other thing, although we all hate it, is comments. You come back to a bit of code a year from now and suddenly realise you haven`t got the foggiest idea what it did, why id did it, what the parameters are meant to be or what it was meant to return
Never assume you won`t have to modify something later
It`s very useful to build up a little library of functions you use a lot - we get to this later in the series (when Boaz lets you see them all <g>)
If anyone has things they thing I should include in Newbie Notes drop me a line - I`m covering quite a wide range of things with the first 10 to see what people wanna read.