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]hugle[/eluser]
[quote author="BaRzO" date="1260401342"][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 ?[/quote]

Hello
You need change your function to:
Code:
->fieldset('Upload Test')
    ->upload('avatar', 'Avatar', '', $config)
    ->indent(150)
    ->submit('Submit')
    ->validate();

after ->validate()
you can use:
Code:
if ($this->form->valid)....

Good luck!


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

[eluser]BaRzO[/eluser]
@mat-moo and @hugle still not working maye my php version is old ? Any idea ?


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

[eluser]Mat-Moo[/eluser]
I use it different via the model, e.g.
Code:
$config=array(
    'upload_path' => $_SERVER[ 'DOCUMENT_ROOT' ].'/assets/images/upload',
    'allowed_types' => 'gif|jpeg|jpg|png',
    'max_size' => '100' // 100KB
);

$this->form
    open('thiscontrol/thisfunction')
    ->upload('fimage','Avatar','',$config)
    ->submit
    ->model('user_model','edit_user')
    ->onsuccess('redirect','thiscontrol/account');

##user_model controller##
function edit_user()
{
    $filenamedata=$this->upload->data();
    if (isset($filenamedata["file_type"]) and ($filenamedata["file_type"]<>""))
    {
        //access file via the $filenamedata["full_path"] var, e.g. to load to database
        //$photo=array(
            'photo' => file_get_contents($filenamedata["full_path"]),
            'type' => $filenamedata["file_type"]
            );
        // you can now add array to database to store photo in database
    }

}
Any use? PS you can use 766 for the CHMOD, don't need Execute for the upload folder


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

[eluser]BaRzO[/eluser]
@mat-moo
there is some typo in your example i have fixed them but still does not work Sad


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

[eluser]hugle[/eluser]
[quote author="BaRzO" date="1260437634"]@mat-moo
there is some typo in your example i have fixed them but still does not work Sad[/quote]

could you please show your example?
controller and model

Sorry, I totally forgot, that UPLOAD data is passed to model only (it'll be fixed soon)

basically you can:
Code:
print_r($data);
in the model, and you'll see the all info you need to ply with the uploaded file Smile


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

[eluser]Mat-Moo[/eluser]
[quote author="BaRzO" date="1260437634"]@mat-moo
there is some typo in your example i have fixed them but still does not work Sad[/quote]
Any clues on "Does not work"? Have you used any debug log messages to see if functions are called and data set? Is the model being called (Which it only will if all your validation is working)

@macigniter Your config looks good and a bit more simple. It's those darn radiogroups that are causing me agro at the moment Smile


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

[eluser]macigniter[/eluser]
[quote author="BaRzO" date="1260401342"]
Code:
Array
(
    [avatar] =>
    [submit] => Submit
)

What is wrong at this ?[/quote]

You've done everything right. The reason why it is not working is because you are using an old version of the library. I have not uploaded the latest version yet since I still want to figure out the best way to implement the prefix/suffix and radio/checkgroups issues.

But, since you guys are so active here you can download the latest build of the library here:
Form Generation Library v0.2.2 (pre-release)

Let me know if it works with this one!


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

[eluser]macigniter[/eluser]
[quote author="Mat-Moo" date="1260457257"]@macigniter Your config looks good and a bit more simple. It's those darn radiogroups that are causing me agro at the moment Smile[/quote]

I know... :-( it's on top of my todo list for the lib. The next version will regard single checkboxes and radiobuttons different than groups. Stay tuned...


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

[eluser]Mat-Moo[/eluser]
I know fieldsets are auto-closed, but what if you want your submit/reset etc. buttons outside of a fieldset? Maybe there needs to be a fieldset(FALSE) which will close the current fieldset (if applicable)?


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

[eluser]macigniter[/eluser]
[quote author="Mat-Moo" date="1260469644"]I know fieldsets are auto-closed, but what if you want your submit/reset etc. buttons outside of a fieldset? Maybe there needs to be a fieldset(FALSE) which will close the current fieldset (if applicable)?[/quote]

check out the latest pre-release. there is a new function exactly as you proposed. with ->fieldset(FALSE) you can close the last fieldset :-)