CodeIgniter Forums
Form Generation Library - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Form Generation Library (/showthread.php?tid=16439)



Form Generation Library - El Forum - 06-12-2009

[eluser]Robert May[/eluser]
The model
Code:
<?php

class Auth_model extends Model {

    var $author_id        = '';
    var $author_name      = '';
    var $author_email      = '';
    var $author_dob          = '';
    var $author_password  = '';
    var $author_lastlogin = '';
    var $author_key       = '';
    var $author_group      = '';

    function Auth_model()
    {
        // Call the Model constructor
        parent::Model();
    }
    
    function login($logindetails)
    {
        $password = md5($logindetails['author_password']);
        $this->db->where('author_name', $logindetails['author_name']);
        $query = $this->db->get('authors', $this);
        if($query->num_rows()>0)
        {
            $user = $query->result_array();
            if($user[0]['author_password'] == $password){
                return $user;
            }
            else {
                return FALSE;
            }
        }
        else
        {
            return FALSE;
        }
    }
    
    function level_check($name)
    {
        $this->db->where('author_name', $name);
           $query = $this->db->get('authors', $this);
        if($query->num_rows()>0)
        {
            $results = $query->result_array();
            $this->db->where('group_id', $results[0]['author_group']);
            $query = $this->db->get('usergroups', $this);
            $query = $query->result_array();
            return $query;
        }
        else {
            return NULL;
        }
    }
    
    function grab_details($name)
    {
        $this->db->where('author_name', $name);
        $this->db->or_where('author_email', $name);
        $query = $this->db->get('authors', $this);
        if($query->num_rows()>0)
        {
            $results = $query->result_array();
            return $results;
        }
        else
        {
            return FALSE;
        }
    }
    
    function list_users()
    {
        $query = $this->db->get('authors');
        $results = $query->result_array();
        return $results;
    }
  
}

/* End of file authors_model.php */
/* Location: ./system/application/models/authors_model.php */



Form Generation Library - El Forum - 06-12-2009

[eluser]Robert May[/eluser]
Oh, and to secure a page all you need is:

Code:
$this->authlogin->require_access('optional_group_requirement');

I hope it's of use to someone Smile
As a note, it uses my own templating library, so switch anything that looks like $this->templater out if you happen to make use of the code.


Form Generation Library - El Forum - 06-12-2009

[eluser]macigniter[/eluser]
@Robert may

Making a field required is as easy as adding the word "required" to the validation string, so in your case you would write

Code:
->text('author_name', 'Username:', 'trim|required|alpha_numeric|max_length[255]|xss_clean', $logindetails['author_name'])

to make the Username field required.

Cheers!


Form Generation Library - El Forum - 06-12-2009

[eluser]Robert May[/eluser]
Ah ha! Many thanks Big Grin
Edit: Works perfectly.


Form Generation Library - El Forum - 06-12-2009

[eluser]macigniter[/eluser]
[quote author="Paul T" date="1244592502"]First of all, thank you for this great time saver! It has already saved me numerous headaches.

I have a feature request: Please add an easy way to include a reCAPTCHA. I would try it myself but I'd just end up mangling the code. Or just point me in the right direction so I know what to mangle?

Thanks!
Paul[/quote]

Hi Paul, this was on my list (besides finally updating the user guide) and I will look into some easy way to add recaptcha support. Have you checked-out this thread:

http://ellislab.com/forums/viewthread/94299/


Form Generation Library - El Forum - 06-15-2009

[eluser]Paul T[/eluser]
[quote author="macigniter" date="1244844619"]

Hi Paul, this was on my list (besides finally updating the user guide) and I will look into some easy way to add recaptcha support. Have you checked-out this thread:

http://ellislab.com/forums/viewthread/94299/[/quote]

Yes, in fact I'm using that helper and have made some mods to your library with good success, allowing me to include my reCAPTCHA with: $form->captcha(). When you do write this into your library, that reCAPTCHA helper is handy.

On a side note, I have spent a good deal of time trying to minimize the usability problems inherent with captchas. For example, someone fills out the form and passes the captcha, but fails to enter a valid email address. At that point, they should not be required to pass the captcha again. But by default, it will be required -- and different -- every time the form reloads.

How I have addressed this is with the jQuery Form Validation Plugin. It is very versatile and easy to implement. Using this method, all fields are validated prior to submitting the form, and the only field that can possibly fail is the captcha. I know there's an AJAX method for reCAPTCHA but I haven't investigated it yet. Not sure I need to.

If someone has a better way of handling this, please share it. I wish I didn't have to use a captcha at all, but you know how that goes.


Form Generation Library - El Forum - 06-16-2009

[eluser]macigniter[/eluser]
Hi Paul, can you please forward your mods to the library (please send to info (at) frankmichel (dot) com) so I can take a look and integrate it into future versions? Maybe I can come up with a solution to that usability issue...


Form Generation Library - El Forum - 06-17-2009

[eluser]Robert May[/eluser]
I was just daydreaming a minute ago, and I realised it would be pretty easy to implement database-created forms using this library. A simple couple of tables of form/fields, with the fields storing the options used in mac's library, you could run a foreach on the fields and build a form dynamically.

The only bit that I can see being difficult is actually processing the fields dynamically, but perhaps it could be made with a flexible DB model. I'm very tempted to give it a shot, as I have some spare time at the moment, but my mind wanders easily!

Opinions? Big Grin


Form Generation Library - El Forum - 06-17-2009

[eluser]macigniter[/eluser]
Do it!! Tongue


Form Generation Library - El Forum - 06-17-2009

[eluser]got 2 doodle[/eluser]
Quote:it would be pretty easy to implement database-created forms using this library

@Robert May

That's cool, I had exactly the same thought but I'm not convinced that it would save any time, but it would be a cool feature to include in a cms.

I don't think processing would be too hard, the table could include
- table name
- field name
- type of control
- action

But when I got to thinking about how to process the form, I started wondering who would benefit. Usually end users are freaked out by editing a text field. I don't know how they would do with creating their own forms. At best the forms would have to be minimal.

doodle