Tulform form generation and validation library |
[eluser]Unknown[/eluser]
Hey there, I was making a site in CodeIgniter, and, having a fair background is hard-typed languages, I wanted to use the correct abstractions. Ask in #C++ on freenode, everyone there will say copy-pasting code from one part of your project to another is always bad. Code should be unique. With such principles in my mind, and knowing how websites generally involve copy-pasting code, I started coding. And yes, I ran into a problem: I had multiple pages with forms, and I had to copy-paste code from one form's controller-view set to another. This obviously didn't seem like the best solution and I decided to write a simple form library. Here is the result. It's a dirty inflexible form library. It handles (or at least it's supposed to handle) form validation and converting field specifications into an HTML string. Now, before you start using my code on your site, please be aware that this is a very rough library, it will most certainly have bugs in it (especially near the field outputting) and you'll also have to modify it to let it suit your needs and layout. I'm posting this just to either get you started, frustrated or some ideas about this subject. This code should definitely not be used it it's current form on any public website. Consequently, I am NOT responsible for any kind of damage this code or this forum message does. I have NOT thoroughly tested this code. Feel free to tell me a bug and it's corresponding fix, I might consider fixing this library, but... whatever, be careful with this library. To use this library, add something along these lines to your controller: Code: $inputs=array( //Simply a 2-dimensional array of fields and their settings Because this weird forum system does not allow me to put more than 6000 characters in one message, I will post the library itself as a new comment in a few seconds.
[eluser]Unknown[/eluser]
This library is hereby released under the New BSD license. See opensource.org for details. Contact me if you need more rights. Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
[eluser]Majd Taby[/eluser]
Hey tulcod, check out the form generation library that comes with CodeExtinguisher (I'd go and check the svn version at http://71.65.20.84:82/svn/codex/trunk ). It is extremely flexible, supports plugins, validation, callbacks, repopulation...everything. It also uses and array to define the form, like your library. When the new version of CodeExtinguisher comes out, I will be releasing the libraries I wrote for it as stand-alone libraries. |
Welcome Guest, Not a member yet? Register Sign In |