[eluser]James V[/eluser]
Well it conflicts with the user guide which shows what checkbox() should generate:
Code: <input type="checkbox" name="privacy" id="akj2we" value="yes" /><label for="akj2we">I agree to the privacy policy</label>
I'm getting name="privacy[]" instead.
[eluser]hugle[/eluser]
[quote author="James V" date="1269868207"]Well it conflicts with the user guide which shows what checkbox() should generate:
Code: <input type="checkbox" name="privacy" id="akj2we" value="yes" /><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
[eluser]mahrizal[/eluser]
great
i use it
[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?
[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
good luck!
[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: <html>
<head>
[removed][removed]
[removed][removed]
[removed][removed]
<title>Demo FGL with JQuery Validation</title>
</head>
<body>
<?php if (! empty($form_errors)) echo $form_errors; ?>
<?php if (! empty($form_contents)) echo $form_contents; ?>
[removed]
<?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);
}
}
}
}
?>
$(document).ready(function(){
$("#my-demo-form").validate({
rules : {
<?php foreach ($rules as $name => $rulestrings){
echo "'$name' : { \n".implode(",\n", $rulestrings). "},\n\n";
}?>
},
});
});
[removed]
</body>
That's it! Easy, isn't it?
[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: <html>
<head>
[removed][removed]
[removed][removed]
[removed][removed]
<title>Demo FGL with JQuery Validation</title>
</head>
<body>
<?php if (! empty($form_errors)) echo $form_errors; ?>
<?php if (! empty($form_contents)) echo $form_contents; ?>
[removed]
<?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);
}
}
}
}
?>
$(document).ready(function(){
$("#my-demo-form").validate({
rules : {
<?php foreach ($rules as $name => $rulestrings){
echo "'$name' : { \n".implode(",\n", $rulestrings). "},\n\n";
}?>
},
});
});
[removed]
</body>
That's it! Easy, isn't it?[/quote]
wow, what a nice sollution, heh, thanks for sharing this, really
it would be also nice to have smth in the core.. like
enable_jquery_validation = true, hehe )
but thanks anyways.
this lib really saves a lot of development time
[eluser]mahrizal[/eluser]
i use this form
and success
but i wanna add captcha in my form
can anybody help me?
[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/us...ptcha.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
|