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-08-2011

[eluser]Davide Bellini[/eluser]
Hi guys!!
Anyone know how to retrieve fields "labels" with ->get_array() method??

Cheers


Form Generation Library - El Forum - 03-14-2011

[eluser]Icehawg[/eluser]
Thanks for the library MacIgniter.

Got a bug for you, though, when using radiogroup.

Code:
ERROR - 2011-03-14 22:44:54 --> Severity: Warning  --> in_array() expects parameter 2 to be array, string given [XXXXX]\libraries\Form.php 1737

Line 1737 looks like this and is contained in the validate() function.

Code:
case 'checkbox':
case 'radio':
$checked = set_value($name);
$this->$element->atts['checked'] = ($checked && in_array($this->$element->value, $checked)) ? TRUE : FALSE;
break;

I moved the case 'radio' down with textarea and hidden, and it seems to be working for me (picking up the correct value).

Code:
case 'hidden':
case 'textarea':
case 'radio':
$this->$element->value = set_value($name);
break;

Am I wrong in doing so? Should I wait a proper bug fix instead?

Thanks again for your library and time.


Form Generation Library - El Forum - 03-20-2011

[eluser]Icehawg[/eluser]
Actually, I started getting the "in_array" error (posted above) with a single checkbox form so I did a little more digging and changed line 1737 from:
Code:
$this->$element->atts['checked'] = ($checked && in_array($this->$element->value, $checked)) ? TRUE : FALSE;

to:

Code:
$this->$element->atts['checked'] = ($checked && in_array($this->$element->value, $this->_make_array($checked))) ? TRUE : FALSE;


Also the select elements were getting the [ ]'s appended to their names even if only one value was selected. So, locally, I removed that and I add the [ ] myself to the name parameter. Not sure if this is a bug, or intentional, but I don't mind adding them in when creating the form->select options.

Thanks again.


Form Generation Library - El Forum - 03-20-2011

[eluser]JonoB[/eluser]
[quote author="Icehawg" date="1300662519"]Actually, I started getting the "in_array" error (posted above) with a single checkbox form so I did a little more digging and changed line 1737 from:
Code:
$this->$element->atts['checked'] = ($checked && in_array($this->$element->value, $checked)) ? TRUE : FALSE;

to:

Code:
$this->$element->atts['checked'] = ($checked && in_array($this->$element->value, $this->_make_array($checked))) ? TRUE : FALSE;


Also the select elements were getting the [ ]'s appended to their names even if only one value was selected. So, locally, I removed that and I add the [ ] myself to the name parameter. Not sure if this is a bug, or intentional, but I don't mind adding them in when creating the form->select options.

Thanks again.[/quote]

Yep, I got the same error too. I fixed it as follows:
From
Code:
case 'checkbox':
case 'radio':
$checked = set_value($name);
$this->$element->atts['checked'] = ($checked && in_array($this->$element->value, $checked)) ? TRUE : FALSE;
break;

To
Code:
case 'checkbox':
case 'radio':
$checked = set_value($name);
$test = TRUE;
if (is_array($checked))
{
  $test = in_array($this->$element->value, $checked) ? TRUE : FALSE;
}
$this->$element->atts['checked'] = ($checked && $test) ? TRUE : FALSE;
break;



Form Generation Library - El Forum - 03-21-2011

[eluser]macigniter[/eluser]
[quote author="Icehawg" date="1300161788"]
ERROR - 2011-03-14 22:44:54 --> Severity: Warning --> in_array() expects parameter 2 to be array, string given [XXXXX]\libraries\Form.php 1737

Am I wrong in doing so? Should I wait a proper bug fix instead?
[/quote]

Did you change the array behaviour of radiogroups, checkboxes and selects BEFORE you got that error message?
This should not happen since all of these elements are handled as arrays by default.

Please confirm that this occurs on a fresh install of the library.


Form Generation Library - El Forum - 03-21-2011

[eluser]Icehawg[/eluser]
Hi MacIgniter. I was using a fresh install of the form gen library and made no modifications at any time. It occurred whether I created a single radio or multiple radios on a page. It also occurred with a single checkbox. (I never tested with multiple checkboxes) I can post the code for my login controller (it had a checkbox) if you wish.

My _make_array($checked) change fixed the problem I believe.


Form Generation Library - El Forum - 03-21-2011

[eluser]Davide Bellini[/eluser]
[quote author="Icehawg" date="1300724670"]Hi MacIgniter. I was using a fresh install of the form gen library and made no modifications at any time. It occurred whether I created a single radio or multiple radios on a page. It also occurred with a single checkbox. (I never tested with multiple checkboxes) I can post the code for my login controller (it had a checkbox) if you wish.

My _make_array($checked) change fixed the problem I believe.[/quote]

The same error occured with multiple checkboxes. I have modified @Icehawg fix [ less code ]:
Code:
$checked = set_value($name);
$verify_check_val = (is_array($checked)) ? (in_array($this->$element->value, $checked) ? TRUE : FALSE) : FALSE;
$this->$element->atts['checked'] = ($checked AND $verify_check_val) ? TRUE : FALSE;
break;

Cheers


Form Generation Library - El Forum - 03-21-2011

[eluser]Icehawg[/eluser]
[quote author="Davide Bellini" date="1300736327"][quote author="Icehawg" date="1300724670"]Hi MacIgniter. I was using a fresh install of the form gen library and made no modifications at any time. It occurred whether I created a single radio or multiple radios on a page. It also occurred with a single checkbox. (I never tested with multiple checkboxes) I can post the code for my login controller (it had a checkbox) if you wish.

My _make_array($checked) change fixed the problem I believe.[/quote]

The same error occured with multiple checkboxes. I have modified @Icehawg fix [ less code ]:
Code:
$checked = set_value($name);
$verify_check_val = (is_array($checked)) ? (in_array($this->$element->value, $checked) ? TRUE : FALSE) : FALSE;
$this->$element->atts['checked'] = ($checked AND $verify_check_val) ? TRUE : FALSE;
break;

Cheers[/quote]

While I would like to take credit for the fix, that fix was provided by JonoB. I simply changed line 1737 to have
Code:
,$this->_make_array($checked)
instead of
Code:
,$checked
.


Form Generation Library - El Forum - 03-21-2011

[eluser]Davide Bellini[/eluser]
Hey guys, I noticed that if I try to set a field with an EMPTY value, the library assign the name of current field to the next field value.

So, if the last field value of a form is empty, the following submit button has the name of this field as a value!

I checked the set_value function and I changed line 2671 adding a return FALSE:
Code:
if ($this->_last_accessed && !$value)
{
  if (!$name) show_error(FGL_ERR.'set_value: No value specified');    
     $value = $name;
     $el = $this->_last_accessed;

     // @MY FIX
     return FALSE;

} else {...

I'm not sure this is the correct way but working for me .. any suggestion??


Form Generation Library - El Forum - 03-23-2011

[eluser]JonoB[/eluser]
I am in the process of trying to integrate model validations with the FormGen library. In essence, I am trying to remove all validation from the controller, and place all of them in the model.

I have this working fine, but I would like the actual error messages to be handled by FormGen - so the outputting/formatting of the error messages is handled automatically.

It means that in some way I have to populate any validation failures into FormGen, but I have no idea on how to do this.

Is this even possible?