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 - 03-29-2010

[eluser]James V[/eluser]
Well it conflicts with the user guide which shows what checkbox() should generate:
Code:
&lt;input type="checkbox" name="privacy" id="akj2we" value="yes" /&gt;&lt;label for="akj2we">I agree to the privacy policy</label>

I'm getting name="privacy[]" instead.


Form Generation Library - El Forum - 03-29-2010

[eluser]hugle[/eluser]
[quote author="James V" date="1269868207"]Well it conflicts with the user guide which shows what checkbox() should generate:
Code:
&lt;input type="checkbox" name="privacy" id="akj2we" value="yes" /&gt;&lt;label for="akj2we">I agree to the privacy policy</label>

I'm getting name="privacy[]" instead.[/quote]

I think it's because userguide is a little outdated...
as for latest version,
listboxes, checkboxes and radios are arrays


Form Generation Library - El Forum - 03-29-2010

[eluser]mahrizal[/eluser]
great
i use it


Form Generation Library - El Forum - 03-29-2010

[eluser]tom.waters[/eluser]
I have succesfully uploaded an image but when I try to save the image file name to a mysql file I get an array to string error.
I know how to handle this with the code igniter framework and the $FILES array but not with the FGL?
can anyone help?


Form Generation Library - El Forum - 03-30-2010

[eluser]hugle[/eluser]
[quote author="tom.waters" date="1269944745"]I have succesfully uploaded an image but when I try to save the image file name to a mysql file I get an array to string error.
I know how to handle this with the code igniter framework and the $FILES array but not with the FGL?
can anyone help?[/quote]

Hello,

Code:
if ($this->form->valid)
        {
            $post = $this->form->get_post(TRUE);
            echo '<pre>';
            print_r($post);
            echo '</pre>';
        }
        else
        {
            $data['errors'] = $this->form->errors;
        }

I think you'll get every information you need after POSTing the image Smile

good luck!


Form Generation Library - El Forum - 03-31-2010

[eluser]dinhtrung[/eluser]
@all : Recently, I'm quite busy with the new project. Would like to thank the author for this greate library that save me alot of codes.
One thing I did for the last project is integrate FGL with jQuery Validate plugins.
You can see the plugin in action here : http://docs.jquery.com/Plugins/Validation/
So this is how I do this, to get both server and client side validation.
First, the server side is a simple FGL form like this:
Code:
# File : controllers/demo.php
# Class : Demo.php
function form()
{
    $this->form->open($this->uri->uri_string(), "my-demo-form")
         ->text('username', 'Username', 'required|alphanumeric|trim')
         ->password('password', 'Password', 'required|min_length[6]')
         ->password('repassword', 'Password Confirmation', 'required|matches[password]')
         ->text('email', 'Email', 'valid_email')
         ->text('address', 'Address', 'max_length[255]')
         ->onsuccess('redirect', '');
    $data['form_contents'] = $this->form->get();
    $data['form_errors'] = $this->form->errors;
    $this->load->view('form', $data);
        
}
So now the view file. I wrote a little translation table for Form validations rules into jQuery validation rules like this:
Of course, the first thing is to load javascript and other stuff from jQuery validation. In the view:
Code:
&lt;html&gt;
&lt;head&gt;
[removed][removed]
[removed][removed]
[removed][removed]
&lt;title&gt;Demo FGL with JQuery Validation&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;?php if (! empty($form_errors)) echo $form_errors; ?&gt;
    &lt;?php if (! empty($form_contents)) echo $form_contents; ?&gt;

[removed]
&lt;?php
$rules = array();
$rulemap = array(
        # "Form_validation rule" => "jquery validation rule",
    'required'    =>    'required : true',
    'matches'        =>    'equalTo : "#%s"',
    'min_length'    =>    'minlength : %d',
    'max_length'    =>    'maxlength : %d',
    'exact_length'    =>    'rangelength : [%d,%d]',
    'alpha'                =>    'lettersonly : true',
    'alpha_numeric'        =>    'alphanumeric : true',
    'alpha_dash'        =>    'letterswithbasicpunc : true',
    'numeric'            =>    'digits : true',
    'integer'            =>    'integer : true',
    'is_natural'        =>    'integer : true',
    'valid_email'        =>    'email : true',
);
foreach ($this->form->_elements as $el){
    if ($name = $el['name']){
    $element = $el['unique'];
    if (!empty($this->form->$element->rules)) {
        $tmprules = explode('|', $this->form->$element->rules);
        foreach ($tmprules as $rule){
             $param = FALSE;
        if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match)){
            $rule    = $match[1];
            $param    = $match[2];
        }
        if (array_key_exists($rule, $rulemap)) $rules[$name][] = sprintf($rulemap[$rule], $param);
        }                    
        }
    }
}
?&gt;
$(document).ready(function(){
    $("#my-demo-form").validate({
         rules : {
        &lt;?php foreach ($rules as $name => $rulestrings){
              echo "'$name' : { \n".implode(",\n", $rulestrings). "},\n\n";
        }?&gt;
            },
    });
});
[removed]
&lt;/body&gt;
That's it! Easy, isn't it?


Form Generation Library - El Forum - 03-31-2010

[eluser]hugle[/eluser]
[quote author="dinhtrung" date="1270074772"]@all : Recently, I'm quite busy with the new project. Would like to thank the author for this greate library that save me alot of codes.
One thing I did for the last project is integrate FGL with jQuery Validate plugins.
You can see the plugin in action here : http://docs.jquery.com/Plugins/Validation/
So this is how I do this, to get both server and client side validation.
First, the server side is a simple FGL form like this:
Code:
# File : controllers/demo.php
# Class : Demo.php
function form()
{
    $this->form->open($this->uri->uri_string(), "my-demo-form")
         ->text('username', 'Username', 'required|alphanumeric|trim')
         ->password('password', 'Password', 'required|min_length[6]')
         ->password('repassword', 'Password Confirmation', 'required|matches[password]')
         ->text('email', 'Email', 'valid_email')
         ->text('address', 'Address', 'max_length[255]')
         ->onsuccess('redirect', '');
    $data['form_contents'] = $this->form->get();
    $data['form_errors'] = $this->form->errors;
    $this->load->view('form', $data);
        
}
So now the view file. I wrote a little translation table for Form validations rules into jQuery validation rules like this:
Of course, the first thing is to load javascript and other stuff from jQuery validation. In the view:
Code:
&lt;html&gt;
&lt;head&gt;
[removed][removed]
[removed][removed]
[removed][removed]
&lt;title&gt;Demo FGL with JQuery Validation&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;?php if (! empty($form_errors)) echo $form_errors; ?&gt;
    &lt;?php if (! empty($form_contents)) echo $form_contents; ?&gt;

[removed]
&lt;?php
$rules = array();
$rulemap = array(
        # "Form_validation rule" => "jquery validation rule",
    'required'    =>    'required : true',
    'matches'        =>    'equalTo : "#%s"',
    'min_length'    =>    'minlength : %d',
    'max_length'    =>    'maxlength : %d',
    'exact_length'    =>    'rangelength : [%d,%d]',
    'alpha'                =>    'lettersonly : true',
    'alpha_numeric'        =>    'alphanumeric : true',
    'alpha_dash'        =>    'letterswithbasicpunc : true',
    'numeric'            =>    'digits : true',
    'integer'            =>    'integer : true',
    'is_natural'        =>    'integer : true',
    'valid_email'        =>    'email : true',
);
foreach ($this->form->_elements as $el){
    if ($name = $el['name']){
    $element = $el['unique'];
    if (!empty($this->form->$element->rules)) {
        $tmprules = explode('|', $this->form->$element->rules);
        foreach ($tmprules as $rule){
             $param = FALSE;
        if (preg_match("/(.*?)\[(.*?)\]/", $rule, $match)){
            $rule    = $match[1];
            $param    = $match[2];
        }
        if (array_key_exists($rule, $rulemap)) $rules[$name][] = sprintf($rulemap[$rule], $param);
        }                    
        }
    }
}
?&gt;
$(document).ready(function(){
    $("#my-demo-form").validate({
         rules : {
        &lt;?php foreach ($rules as $name => $rulestrings){
              echo "'$name' : { \n".implode(",\n", $rulestrings). "},\n\n";
        }?&gt;
            },
    });
});
[removed]
&lt;/body&gt;
That's it! Easy, isn't it?[/quote]

wow, what a nice sollution, heh, thanks for sharing this, reallySmile
it would be also nice to have smth in the core.. like
enable_jquery_validation = true, heheSmile)

but thanks anyways.
this lib really saves a lot of development time


Form Generation Library - El Forum - 03-31-2010

[eluser]mahrizal[/eluser]
i use this form
and success
but i wanna add captcha in my form
can anybody help me?


Form Generation Library - El Forum - 04-01-2010

[eluser]hugle[/eluser]
[quote author="mahrizal" date="1270111710"]i use this form
and success
but i wanna add captcha in my form
can anybody help me?[/quote]

Hi.
you can use built-in recaptcha : http://www.frankmichel.com/formgenlib/user_guide/elements/recaptcha.html

Good luck


Form Generation Library - El Forum - 04-01-2010

[eluser]mahrizal[/eluser]
[quote author="hugle" date="1270121627"][quote author="mahrizal" date="1270111710"]i use this form
and success
but i wanna add captcha in my form
can anybody help me?[/quote]

Hi.
you can use built-in recaptcha : http://www.frankmichel.com/formgenlib/user_guide/elements/recaptcha.html

Good luck[/quote]

thanks hugle

i ever read and used it
i also got private and public key on recaptcha.net
but i find some errors

i don't know how to use it combine with this form

yeah probably i have to try again