PHP Form creation and basic validation
As a developer and web designer, the most frustrating part I have found is when working with forms.
Long time ago (about 2 years now) I start putting togheter few PHP function trying to make my life a lot easier, but never got the time to finish it off.
Finally I have put everything on the side and got cracking on this due to a new project that involves the making a few very long forms.
The thought of writing all the html code (tables or DIVs) and validate them made me go back to this little project and decided to give it more thoughts.
This is the first release of the PHP code for this project so, if you would like to give it a bash and make use of it please do so…
A sample can be found here: SAMPLE PHP FORM
Some of the features:
- Choice of using TABLE or DIVs for layout
- You can create more than one form on the same page making sure the right one is validated on submission
- Basic form validation
- Option to make the field required or not
- Show ERROR message beside the required field – standard
- Option to set the ERROR message text – set to REQUIRED in the sample form
- Show ERROR message at the top of the form as well - optional
- Cuts form creation time in more than half
- Automatically sets the values of the field after posting the form
- Option to add javascript code to the field (e.g. for use with ajax, etc)
- and much more…
If you find any errors and anything that could help improve the functionality of this project, please leave a comment and I’ll make sure it gets done ASAP.
Tags: PHP create form fields function, php forms

















February 13th, 2010 at 11:57 pm
Hi Paul,
Thanks for dropping around and thanks for the ideas.
* security – can be easily implemented
* CAPTCHA – will be added to the next update (already done but not finished)
* characteres counter – there is an option to add javascript to the end of the field (e.g. onfocus, etc) which can call a JS function
* email – that’s done already in my sample as for DB has to be done manually by the user as there is no way to know the DB name, table name and fields….
ANyway, once againg thanks for the good points.