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 - 11-27-2009

[eluser]Mat-Moo[/eluser]
@dinhtrung - Perfect, added your mod and works a treat, would love to see this as official Smile


Form Generation Library - El Forum - 11-29-2009

[eluser]dinhtrung[/eluser]
Found a bug in Form->submit() and Form->reset(), maybe Form->button(), either.
First, I change this line to enable error message even if el['name'] cannot be found by _el_get_unique($name)
Code:
@@ -2015,8 +2017,7 @@
         }
         else
         {
-            show_error(FGL_ERR.'add_error: Element name "'.$name.'" does not exist');
+            $this->error_string .= $this->error_open.$message.$this->error_close;
         }        
         return $this;
So the problem is triggered only when I bypass the nameid parameters for submit(), reset() and button(). It is because Form Generation didn't record the status of this field, because it did not know the name or id of these field.
In the form, I still found <input type='submit' name='Submit' id='submit'> when I run $form->submit('Submit'), but when I submit, the same form appears, like nothing happens at all.
This patch will just help fix submit() and reset().
Code:
@@ -1264,6 +1264,7 @@
     function submit($value='Submit', $nameid='', $atts=array())
     {
         $info = $this->_make_info($atts);
+        if (! $nameid) $nameid = 'submit';
         $this->_make_nameid($nameid, $info);
         $this->_check_name($info['name']);        
         $info['type'] = 'submit';
@@ -1276,6 +1277,7 @@
     function reset($value='Reset', $nameid='', $atts=array())
     {
         $info = $this->_make_info($atts);
+        if (! $nameid) $nameid = 'reset';
         $this->_make_nameid($nameid, $info);
         $this->_check_name($info['name']);
         $info['type'] = 'reset';



Form Generation Library - El Forum - 11-29-2009

[eluser]Mat-Moo[/eluser]
@dinhtrung After applying your patch (before/after) stuff I now have a minor issue Sad As I''m trying to use radio groups, I want
Code:
<div><label>blah blah blah</label>Radio button/Text, Radio button text</div>
Of course each radio button is treated as a seperate entity so now I get
Code:
<div><label>blah blah blah</label>Radio button</div>
<div><label>blah blah blah</label>Radio button</div>
<div><label>blah blah blah</label>Radio button</div>
Seems it needs some seperation for Radio groups and Radio inputs?


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

[eluser]dinhtrung[/eluser]
Yes, just apply this patch, and configure the library through its config/form.php with these:
Code:
$config['wrappers'] = array(
    'label' => array(    // this applies to all labels
        'prefix' => '<p>',
        'suffix' => '<br>',
    ),
    'label|checkbox' => array(    // this only applies to labels of checkboxes
        'prefix' => '',
        'suffix' => '',
    ),
    'label|radio' => array(    // this only applies to labels of radios
        'prefix' => '',
        'suffix' => '',
    ),
    'text' => array(
        'prefix' => "\t\t",
        'suffix' => '</p>',
    ),
    'password' => array(
        'prefix' => "\t\t",
        'suffix' => '</p>',
    ),    
    'upload' => array(
        'prefix' => "\t\t",
        'suffix' => '</p>',
    ),
    'checkbox' => array(
        'prefix' => "\t\t",
        'suffix' => '</p>',
    ),
    'radio' => array(
        'prefix' => "\t\t",
        'suffix' => '</p>',
    ),
    'submit' => array(
        'prefix' => "\t\t",
        'suffix' => '</p>',
    ),
    'reset' => array(
        'prefix' => "\t\t",
        'suffix' => '</p>',
    ),
    // always define defaults for specific elements (below) after defaults by element type (above)
    'multiple' => array(
        'prefix' => "\t\t",
        'suffix' => '</p>',
    )
);
Don't know why I didn't do this earlier Smile .
Another improvement is open() methods. For now, if you don't specify the action URL, the current url ($this->uri->uri_string()) is used.


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

[eluser]hugle[/eluser]
[quote author="dinhtrung" date="1259921990"]
Don't know why I didn't do this earlier Smile .
Another improvement is open() methods. For now, if you don't specify the action URL, the current url ($this->uri->uri_string()) is used.[/quote]

I was already thinking about that, and wanted to ask macigniter to include this alsoSmile))
now he have to apply the patchSmile

this lib is amazing Smile


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

[eluser]Mat-Moo[/eluser]
@dinhtrung Thanks for your efforts, although I still could not get the formatting I required. A simple line wrapper maybe the best solution, that would be applied to every item. That could work for various options, e.g. <div> / </div>, <li> / </li> and keep each entity separate?


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

[eluser]dinhtrung[/eluser]
@Mat-Moo : With the attached Form library in $config['wrapper'], I think you can render almost all structure of Form. Although it's more complex, but now you can separate the wrapper of label for some input type, and use another wrapper for others.
The only thing left behind is the label position. In Form Gen, the label is put before or above for text, password, textarea, select but after for checkbox, radiobox. I think I'll add this feature later.
Can you post your form structure to here? I'll try to extend the lib to support it. Big Grin


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

[eluser]dinhtrung[/eluser]
Tonight I tried to build a select box from Form Generation, and found out that the field always return an array.
Code:
$single = array(
    1 => 'One',
    2 => 'Two',
    3 => 'Three'
);
$this->form->open()
    ->select('single', $single, 'Single Select', 2);
echo $this->form->get();
Will produce:
Code:
<label for="single" class="left">Single Select</label>        
<select name="single[]" id="single">
<option value="1">One</option>
<option value="2" selected="selected">Two</option>
<option value="3">Three</option>
</select></p>
This is in CI 1.7.2. Don't know how to fix this.. Sad


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

[eluser]macigniter[/eluser]
[quote author="Mat-Moo" date="1259353603"]@dinhtrung - Perfect, added your mod and works a treat, would love to see this as official Smile[/quote]

Hi Everyone, I actually spent today on implementing this feature as well as cleaning out some other things. I will release the updated official version soon.

Although I agree that it would be nice to add more stuff to the library I really want to keep it as clean as possible and don't integrate every possible thing somebody might need. Just like CI itself is giving us the basics to work with I would like to keep this library clean and just help doing basic stuff. Anything else should be no problem to add manually or with some jQuery magic :-)


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

[eluser]macigniter[/eluser]
[quote author="hugle" date="1259931255"][quote author="dinhtrung" date="1259921990"]
Don't know why I didn't do this earlier Smile .
Another improvement is open() methods. For now, if you don't specify the action URL, the current url ($this->uri->uri_string()) is used.[/quote]

I was already thinking about that, and wanted to ask macigniter to include this alsoSmile))
now he have to apply the patchSmile

this lib is amazing Smile[/quote]

This will be included. Good one!