I'm new to PHP, and i'm working on a free headphone database website- yes it would be used - to help me learn PHP. FYI i'm a professional Java programmer. If someone could have a quick read of this and let me know if they can see any flaws in my design pattern i'd be most appreciative 🙂
I'm using the smarty templating system. I was using VDaemon for validation, but it didn't play nice with my debugger (which I really need for learning php) so i'm rolling my own. I only need simple validation anyway.
Basically a form is submitted to PHP, I use my own validation library to check the fields (ie is a number, is a URL, etc), and if there's an error the name of the field's added to an array and the form's redisplayed. If the name of a field is in that array (checked with in_array()) then it's highlighted red. eg (ignore trivial errors)
{if (in_array($errors, 'name'))}
<td>(in red)Field name</td>
{else}
<td>field name</td>
{/if}
The PHP script also adds all the values submitted to another array so that the user doesn't have to retype everything if they make one error. I just use something like this
<input type="text" value="{$fields.name}"> (this is smarty syntax)
Does this look ok? Can anyone suggest a better way to do it? Thanks for your time 🙂