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

[eluser]hugle[/eluser]
Hello,

the GET should go before ->valid.

What I mean, you firstly should have:

$data['form'] = $this->form->get();
...
...
if( $this->form->valid )
{
//code
}

(but not wise-verse)

good luckSmile


Form Generation Library - El Forum - 02-05-2010

[eluser]seanloving[/eluser]
[quote author="hugle" date="1265251766"]Hello,

the GET should go before ->valid.

What I mean, you firstly should have:

$data['form'] = $this->form->get();
...
...
if( $this->form->valid )
{
//code
}

(but not wise-verse)

good luckSmile[/quote]

@hugle- that makes sense, but it does seem to work either way. Also, it seems like ->onsuccess( 'redirect', .. ) comes automatically before ->get().

What am I missing?


Form Generation Library - El Forum - 02-09-2010

[eluser]Mat-Moo[/eluser]
I've been so busy with a project that I was unable to update to version 1... till tonight! So far I've managed to get the new version to almost everything I need, but I'm still having issues with radios groups, grrr.
I required the following setup
Code:
<div>
<label>Field name</label>
&lt;input radio&gt;&lt;label value 1>1</label>
&lt;input radio&gt;&lt;label value 2>2</label>
&lt;input radio&gt;&lt;label value 3>3</label>
</div>
But I'm struggling to get this to happen, I've managed to get all my other fields to work, form layout
Code:
&lt;form&gt;
<fieldset>
  <legend>legend</legend>
  <div class="fields">
   <div><label x>x</label>&lt;input&gt;&lt;/div>
  </div>
</fieldset>
&lt;/forms&gt;
In action http://www.mbamatch.com/account/register_emp
Can you help me sort these radios groups!


Form Generation Library - El Forum - 02-10-2010

[eluser]Maglok[/eluser]
First define the array of options:

Code:
$field[] = array('1', 'Value 1');
$field[] = array('2', 'Value 2');
$field[] = array('3', 'Value 3');

Then add it to the form

Code:
->radiogroup('fieldname', $field, 'Label:', DEFAULT_VALUE)
The last being the default value you want.

More on this in the user_guide: http://www.frankmichel.com/formgenlib/user_guide/elements/radiogroup.html

Be aware that it returns an array (for now) so you will need to go something like:

Code:
$value = $form['fieldname'][0];



Form Generation Library - El Forum - 02-10-2010

[eluser]Mat-Moo[/eluser]
@Maglok, Who are you talking to? Because if that was a response to me, then I suggest you read my query again.


Form Generation Library - El Forum - 02-10-2010

[eluser]Maglok[/eluser]
Oh wait you want the label on the right? There is a 'position' => 'after' default on the radiogroups in form.php (the config file). If that is not it I do not understand your query. Wink


Form Generation Library - El Forum - 02-10-2010

[eluser]Mat-Moo[/eluser]
My issue is that I can't get a DIV to surround the radio group and group label.
Code:
'radio' => array(
        'class' => 'small',
        'label_prefix' => '<div>',        // wraps around labels
        'label_suffix' => '',
        'field_prefix' => '',         // wraps around fieldsets (inside), inputs, buttons, textareas, selects, captchas & recaptchas
        'field_suffix' => '</div>',
        'label' => array(
            'position' => 'after',
            'class' => 'auto',
            'label_prefix' => '',        // wraps around labels
            'label_suffix' => '',
            'field_prefix' => '',         // wraps around fieldsets (inside), inputs, buttons, textareas, selects, captchas & recaptchas
            'field_suffix' => ''
        )
But it doesn't work as expected.


Form Generation Library - El Forum - 02-10-2010

[eluser]Maglok[/eluser]
Checkgroups and radiogroups use the 'group_prefix' and 'group_suffix' settings not field or label. That might be it.

If it just has to work you can 'hardcode' it by use the html() function:

Code:
->html('<div>')
->radiogroup()
->html('</div>')



Form Generation Library - El Forum - 02-10-2010

[eluser]Mat-Moo[/eluser]
Thanks for you r help, but group_prefix is inserted before the first item in the group, and not the group label, e.g.
Code:
<label for group><group_prefix><radio><label><radio><label></group_suffix>
This could well be a minor bug, and maybe I just need to hack the form creation to get this to wrap correctly.
I was trying to avoid hardcoding as I am using this in a live project with a number of forms, and was just hoping to get it to work Smile


Form Generation Library - El Forum - 02-10-2010

[eluser]macigniter[/eluser]
[quote author="Mat-Moo" date="1265831717"]Thanks for you r help, but group_prefix is inserted before the first item in the group, and not the group label, e.g.
Code:
<label for group><group_prefix><radio><label><radio><label></group_suffix>
This could well be a minor bug, and maybe I just need to hack the form creation to get this to wrap correctly.
I was trying to avoid hardcoding as I am using this in a live project with a number of forms, and was just hoping to get it to work Smile[/quote]

Hi there, it's not a bug, it's a feature ;-) Seriously, that's the way it's supposed to work. If you would like to insert the div before and after the whole group including label you need to code it with

Code:
->html('<div>')
->radiogroup()
->html('</div>')

as suggested by Maglok.