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

[eluser]Sixteh[/eluser]
Okay, my problem seems to be something wrong with my config/setup on my server. =/ The validation doesn't work at all on my server, but it works perfectly on wamp localhost.


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

[eluser]groyk[/eluser]
Hi

I am new to CI and Form generator

I just have one simple question.

One of my controllers contains multiply forms. In the form generator I need something like
Code:
$this->form->destroy();

Else when I call
Code:
$this->form->open('my_form')

I still get the output from the first.

In short I would like to do like this

Code:
<?

class Users extends Controller {

    function Users() {
        
        parent::Controller();

    }

    function index() {
        
        
        
        $data["title"] = "User handling";
        $data["stylesheets"][] = "users.css";
        
            $this->load->library('userlib');
        
            $users = $this->db->query("SELECT * FROM users ORDER BY username");
            
        # Forms
            $this->load->library('form');
            
            $i=0;
            foreach($users->result() as $u):    
                # Prints all rows to array
                    foreach($u as $key=>$r) {
                        $data['users'][$i][$key] = $r;
                    }
                
                $id = $data['users'][$i]['id'];
                
                # Form 1. Delete User
                    $this->form->open('users','delete_user_'.$id)
                    ->hidden('id'.$id,$id)
                    ->submit('Submit')
                    ->model('users', 'delete')
                    ->onsuccess('redirect', 'welcome/success');
                                    
                    $data['users'][$i]['form_delete'] = $this->form->get();
                
                # Form 2. Edit user - Only for showing that this approach not working
                    $this->form->open('users','edit_user_'.$id)
                    ->hidden('id',$id)
                    ->submit('Submit')
                    ->model('users', 'edit')
                    ->onsuccess('redirect', 'welcome/success');
                    
                    $data['users'][$i]['form_edit'] = $this->form->get();
                
                $i++;
            endforeach;
                
        
        $this->load->library('layout');
        $this->layout->setLayout('layouts/main');
        $this->layout->view("users/view",$data);

    }
}

?>



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

[eluser]macigniter[/eluser]
[quote author="echoDreamz" date="1252837760"]@macigniter where am I setting the full path for the uploads?[/quote]

You would supply it as an attribute like this:

Code:
$config = array(
   'upload_path' => 'os_files',
   'max_size'    => '20000'
);

$this->form->upload('file' , 'Upload File:', true, $config);

Please see details for the config values in the CI user guide.


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

[eluser]macigniter[/eluser]
[quote author="groyk" date="1252946144"]
One of my controllers contains multiply forms. In the form generator I need something like
Code:
$this->form->destroy();

Else when I call
Code:
$this->form->open('my_form')

I still get the output from the first.
[/quote]

This will be available in the next version! I will hope to release it soon. If you need that function instantly, feel free to insert this code right after the Form() function:

Code:
function flush()
    {
        $this->fieldsets = 0;
        $this->indented = 0;
        $this->columns = 0;
        
        $this->action = '';
        $this->method = 'post';
        $this->multipart = FALSE;
        $this->atts = array();
    
        $this->_elements = array();
        $this->_labels = array();
        $this->_aliases = array();
        $this->_names = array();
    
        $this->_last_accessed = '';
        $this->_output = '';
    
        $this->_submit_name = array();
        $this->_posted = FALSE;
            
        $this->_files = array();
        $this->_data = array();
    
        $this->_onsuccess = array();
        $this->_postprocess = array();
            
        $this->error = array();
        $this->errors = '';
        
        $this->error_string = '';
    
        $this->model = '';
        $this->model_method = '';
        $this->model_data = '';
        
        $this->valid = FALSE;
        $this->validated = FALSE;
        
        $this->recaptcha = FALSE;
        $this->recaptcha_error = '';    
    }

You can then use:

Code:
$this->form->flush();

in between two forms in the same controller. Don't forget to clear out the $data['form'] and/or $data['errors'] variables.


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

[eluser]echoDreamz[/eluser]
@macigniter - I have still not figured out how to solve the upload issue. Where do I set the upload path for your library?


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

[eluser]groyk[/eluser]
Quote:This will be available in the next version! I will hope to release it soon. If you need that function instantly, feel free to insert this code right after the Form() function:

You can then use:

Code:
$this->form->flush();

in between two forms in the same controller. Don't forget to clear out the $data['form'] and/or $data['errors'] variables.

Thank you for this fast update. Now the Libary outputs multiply forms quite simple.

However I can't get validation to work :-S

Here is how I generate my forms

Code:
foreach($users->result() as $u):    
                # Prints all rows to array
                    foreach($u as $key=>$r) {
                        $data['users'][$i][$key] = $r;
                    }
                
                    $id = $data['users'][$i]['id'];
                    
                    # Form 1. Delete User
                        $del = $this->form->open('users','delete_user_'.$id)
                        ->hidden('id',$id)
                        ->submit('Delete')
                        #->model('users', 'delete')
                        ->onsuccess('redirect', 'welcome/success')
                        ->get();
                        
                        $this->form->flush();                
                        $data['users'][$i]['form_delete'] = $del;
                    
                    
                    # Form 2. Edit user - Only for showing that this approach not working
                        $this->form->open('users','edit_user_'.$id)
                        ->text('id',$id,'required|trim|exact_length[2]')
                        ->set_error("TESTING")
                        ->nobr()
                        ->submit('Edit')
                        ->onsuccess('redirect', 'welcome/success');
                        
                        $edit = $this->form->get();
                        $errors = $this->form->errors;
                        $this->form->flush();
                        
                        $data['users'][$i]['form_edit'] = $edit;
                        $data['users'][$i]['errors_edit'] = $errors;

                $i++;
            endforeach;



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

[eluser]groyk[/eluser]
Hi macigniter

I think I found a small bug in the libary

I have attatched following attributs to a "submit" button

Code:
$del_att = array('onclick' => "confirm('Are yo sure you want to delete?')");

It works fine, except that if you press cancel the library still redirect to the success page!


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

[eluser]groyk[/eluser]
Quote:Thank you for this fast update. Now the Libary outputs multiply forms quite simple.

However I can't get validation to work :-S

Don't know what I did wrong!! Now the validation is working!

I must have done something wrong in my view.


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

[eluser]echoDreamz[/eluser]
@groyk I am not 100% sure, but shouldnt you "return confirm();"


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

[eluser]groyk[/eluser]
[quote author="echoDreamz" date="1253144867"]@groyk I am not 100% sure, but shouldnt you "return confirm();"[/quote]

Hi echoDreamz

Thank you, that did the trick!

Stupid me, just copy pasted from another script!