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 - 12-09-2009

[eluser]macigniter[/eluser]
[quote author="Mat-Moo" date="1260330319"]
What bit do you need help with? I'm really behind with some stuff at the moment but would love to help back as a donation.[/quote]

Please take a look at the user guide's table of content. All the light grey pages are not finished yet. It would be great if especially the "Methods" could be finished. Feel free to write up any method you feel comfortable with.


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

[eluser]macigniter[/eluser]
[quote author="BaRzO" date="1260151149"]how can i use iupload or upload ? pls give a snippet...[/quote]

Please read the user guide on the upload() element.


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

[eluser]macigniter[/eluser]
@everyone:

I am trying to implement the prefix/suffix thing in the best way possible. Therefore I would like to know how and WHERE you would need the prefixes and suffixes within your form.

Please give me a short code example like this:

Code:
// my suggestion of a prefix/suffix implementation
// i'm not a fan of a per element configuration and
// rather would have a global configuration of:
//
// element prefix/suffix
// fieldset prefix/suffix
// label prefix/suffix
// input prefix/suffix
//
// and then turn it off for specific elements with a
// last accessed method like ->nowrap() or something like that
<form>

{fieldset_outside_prefix}
<fieldset>
<label></label>
{fieldset_inside_prefix}

{element_prefix}
{label_prefix}<label>Input</label>{label_suffix}
{input_prefix}&lt;input type="" /&gt;{input_prefix}
{element_suffix}

{element_prefix}
{label_prefix}<label>Textarea</label>{label_suffix}
{input_prefix}&lt;textarea&gt;&lt;/textarea>{input_prefix}
{element_suffix}

{fieldset_inside_suffix}
</fieldset>
{fieldset_outside_suffix}

&lt;/form&gt;

Which position would you prefer for fielsets? inside or outside?

I understand that groups of checkboxes or radiobuttons are a little tricky and need special treatment. Therefore the suggested {element} prefix/suffix which would wrap around the whole group. The wrapper for the single radios/checkboxes inside could then be ignored or turned off by using ->nowrap()

Code:
// sample for a group of checkboxes

{element_prefix}
{input_prefix}&lt;input type="checkbox" /&gt;{input_prefix}
{label_prefix}<label>Check #1</label>{label_suffix}

{input_prefix}&lt;input type="checkbox" /&gt;{input_prefix}
{label_prefix}<label>Check #2</label>{label_suffix}
{element_suffix}

// sample for a group of checkboxes
// with the use of $this->form->checkgroup(..)->nowrap('input|label')

{element_prefix}
&lt;input type="checkbox" /&gt;
<label>Check #1</label>

&lt;input type="checkbox" /&gt;
<label>Check #2</label>
{element_suffix}

Please let me know what you think!


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

[eluser]dinhtrung[/eluser]
@macigniter : I've already cover this issue in my patch.
In the configuration, just like your default item:
Code:
$config['nowrap'] = FALSE;
$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>',
    ),
    'multiple' => array(
        'prefix' => "\t\t",
        'suffix' => '</p>',
    )
);
I implement another function : wrap() to toggle between adding prefix, suffix for elements.
I think another thing Formgen should consider is the label position. For now, radio and checkbox has label after input, and there's no way to put them before input.
I usually write form in BlueprintCSS standards:
Code:
<fieldset><legend>Login</legend>
<p><label>Username</label><br>
   &lt;input name='username' type='text' value='&lt;?= set_value('username', $username); ?&gt;'/&gt;&lt;/p>
<p><label>Password</label><br>
   &lt;input name='password' type='password' value=''/&gt;&lt;/p>
<p>
</fieldset>
<fieldset>
          <legend>Select, checkboxes, lists</legend>
          <p>
            <label for="dummy3">Select field</label><br>
            <select id="dummy3" name="dummy3">
              <option value="1">Ottawa</option>
              <option value="2">Calgary</option>
              <option value="3">Moosejaw</option>
            </select>
          </p>
          <p>
            <label for="dummy4">Select with groups</label><br>
            <select id="dummy4" name="dummy4">
              <option>Favorite pet</option>
              <optgroup label="mammals">
                <option>dog</option>
                <option>cat</option>
                <option>rabbit</option>
                <option>horse</option>
              </optgroup>
              <optgroup label="reptiles">
                <option>iguana</option>
                <option>snake</option>
              </optgroup>
            </select>
          </p>
          <p><label>Radio buttons</label><br>
            &lt;input type="radio" name="example"&gt; Radio one<br>
            &lt;input type="radio" name="example"&gt; Radio two<br>
            &lt;input type="radio" name="example"&gt; Radio three<br>
          </p>
          <p><label>Checkboxes</label><br>
            &lt;input type="checkbox"&gt; Check one<br>
            &lt;input type="checkbox"&gt; Check two<br>
            &lt;input type="checkbox"&gt; Check three<br>
          </p>
        </fieldset>



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

[eluser]macigniter[/eluser]
[quote author="dinhtrung" date="1260395864"]@macigniter : I've already cover this issue in my patch.[/quote]

Argh... 'short' example :-)

I have already seen your modification and referred to it in the previous post. But I am not quite happy with this approach and therefore would like to ask more people on what their specific requirements are.

PS: I am really trying to keep this library free of any specific requirements. Since not everyone is using jQuery, a CSS framework like Blueprint or CRUD I am only implementing core features here. Everyone is free to modify the library for personal requirements, but I would really like to maintain the core library updates from here.


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

[eluser]dinhtrung[/eluser]
@macigniter : Sorry, skim too much :">
I have seen form with inside suffix for fieldsets, like jQuery-UI themeroller sidebar, they use dl to create the sidebar.
Some form can use ul, ol as well. Maybe that would fit.


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

[eluser]hugle[/eluser]
Hello macigniter and dinhtrung

well, I think i've read all your both posts...
what about: prefix/suffix support etc.
Personnaly I like the path dinhtrung posted. As far as looking at it, I can't see any problems with it...

@macigniter, what you don't like in his approach? can you expain? so we could take a deeper look?
btw, I'l try to write something for ya this week, but.. you'll need to fix grammar errors Tongue


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

[eluser]macigniter[/eluser]
It's too much configuration.

dinhtrung's BlueprintCSS standard example could be easily done with:

Code:
$config['element_prefix']     = '<p>';
$config['element_suffix']     = '</p>';
$config['fieldset_open']     = '';
$config['fieldset_close']     = '';
$config['label_prefix']     = '';
$config['label_suffix']     = '<br />';
$config['input_prefix']     = '';
$config['input_suffix']     = '';

Along with some additional settings for the checkboxes/radiobuttons respective checkgroups/radiogroups and a ->nowrap() method for handling exceptions I think that there don't need to be 40 lines of config code.

I really think that my approach (see above) can cover it all and we can get rid of the "break_after" setting.


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

[eluser]BaRzO[/eluser]
[quote author="macigniter" date="1260380294"][quote author="BaRzO" date="1260151149"]how can i use iupload or upload ? pls give a snippet...[/quote]

Please read the user guide on the upload() element.[/quote]

I am using
Code:
barzo@laptop:~$ uname -a
Linux laptop 2.6.28-15-generic #49-Ubuntu SMP Tue Aug 18 18:40:08 UTC 2009 i686 GNU/Linux

------
barzo@laptop:~$ php -v
PHP 5.2.6-3ubuntu4.2 with Suhosin-Patch 0.9.6.2 (cli) (built: Aug 21 2009 19:14:44)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies

uploads dir chmod 777

My Controller
Code:
function index()
{
    $config = array(
    'upload_path' => '/var/www/ci_formlib/uploads',
    'allowed_types' => 'pdf|zip',
    'max_size' => 4000
    );

    $this->form->open('controller/index')

    ->fieldset('Upload Test')
    ->upload('avatar', 'Avatar', '', $config)
    ->indent(150)
    ->submit('Submit')
    ->onsuccess('redirect', 'controller/success');
    $this->form->validate();
    if ($this->form->valid)
    {
        $post = $this->form->get_post();
        die("<pre>".print_r($post)."</pre>");
    }
    $data['form'] = $this->form->get();
    $this->load->view("form", $data);
}

and i get
Code:
Array
(
    [avatar] =>
    [submit] => Submit
)

What is wrong at this ?


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

[eluser]Mat-Moo[/eluser]
Upload is done via the upload class, so the data you want is in $this->upload->data();
http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html