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-21-2009

[eluser]2think[/eluser]
Frank and hugle, thanks for the extremely intelligent and helpful explanations.


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

[eluser]combatCoder[/eluser]
Ok, quick question on the form open, it appears that no matter what I put in as the action it is getting over written by the base url.
I’m using the latest version: 0.2.2 Pre-release
Example:
Code:
Class Report extends Controller {
    function Report()
    {
        parent::Controller();
    }

    function index()
    {
    $this->load->library('form');
    $type = array(
        'default'  => '--- Select a Report ---',
        '1'        =>    'Create an One Report',
        '2'        =>    'Create an Two Report',
        '3'        =>    'Create an Three Report',
        '4'        =>    'Create an Four Report',
        '5'        =>    'Create an Five Report'
    );
    $this->form->open('report','picker')
    ->label('Please Select the desired Report:','type')
    ->br()
    // Using the onChange function to submit the form
    ->select('type',$type,'','default','onChange="this.form.submit();"');
    $data['form'] = $this->form->get();
    $data['errors'] = $this->form->errors;
    $this->load->view('report_view', $data);
    }
}

When the view loads I get:
A PHP Error was encountered
Severity: Notice

Message: Undefined variable: action

Filename: libraries/Form.php

Line Number: 1521

and the form tag looks like this:
<form action="http://localhost/test/" method="post">

Suggestions, thoughts? Man I think this might be something small, but I can not see what it is atm...
Thanks in advance for the assistance.


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

[eluser]2think[/eluser]
combatCoder,

I'm not an expert but will try to help.

1. Base_url should be set in your config application/config.php so I'm thinking that is a problem. But why are you setting $report = $this->form->open? The reason I ask is because later on in your code, you set the data['errors'] and data['form'] not to $report->form-get() or $report->form->errors.

2. Not familiar with the pre-release lib but it's clearly the $action variable is not set but is used near line 1521, hope Frank or someone more knowledgeable can help on that. I'm using the stable release without any problems.


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

[eluser]combatCoder[/eluser]
Quote:But why are you setting $report = $this->form->open?
Just started testing an idea, I noticed it was there and thought about taking it out. The form->open broke so I did not get that far in testing my idea 8->. Removed it from the original post so as not to confuse it with the issue at hand. Thanks though, knew I should of removed that 8-).

Here is some more info on my config setup:
Code:
/** autoload.php **/
$autoload['libraries'] = array('database', 'session');
$autoload['helper'   ] = array('form','url');

/** config.php **/
$config['base_url']    = "http://localhost/test/";

Also, I am using XAMPP for windows, on Windows 7, and my editor is Eclipse.
Just not sure why it is over-writing my form action and using the base_url.

Did I forget to complete a set when I updated to the newer version?
Man, I need a beer now... 8-)
Thanks for the assist again.


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

[eluser]Sinclair[/eluser]
Hi,

It is not working for me:

In the controller:
Code:
function index()
    {    
        $this->load->library('form'); // first of all we have to load the library
        
        $this->form // then we fill the form with elements
        ->open('login')
        ->text('username', 'Your Username', 'trim|alpha_numeric|max_length[30]|xss_clean')
        ->pass('password', 'Your Password', 'trim|alpha_numeric|max_length[20]|xss_clean')
        ->indent(200)
        ->checkbox('loggedin', 'yes', 'I want to stay logged-in')
        ->submit()
        ->reset()
        ->onsuccess('redirect', 'login/success');
        
        $data['form'] = $this->form->get(); // this returns the validated form as a string
        $data['errors'] = $this->form->errors;  // this returns validation errors as a string
        
        $this->load->view('welcome_message', $data);
    }


And on the view:
Code:
<?=$errors?>
<?=$form?>

And I just got nothing on the screen. What could be wrong?


Best Regards,


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

[eluser]macigniter[/eluser]
[quote author="Sinclair" date="1261581311"]And I just got nothing on the screen. What could be wrong?[/quote]

Everything you posted is correct. So if you really get nothing on the screen it looks like you have an error somewhere else in your controller. Did you validate your php?


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

[eluser]macigniter[/eluser]
[quote author="combatCoder" date="1261518786"]
Suggestions, thoughts? Man I think this might be something small, but I can not see what it is atm...
Thanks in advance for the assistance.[/quote]

The pre-release has a bug in that case. Please modify your Form.php as follows:

In the function _get_form_open() substitute

Code:
if ($this->multipart) return form_open_multipart($action, $this->atts);
return form_open($action, $this->atts);

with

Code:
if ($this->multipart) return form_open_multipart($this->action, $this->atts);
return form_open($this->action, $this->atts);



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

[eluser]combatCoder[/eluser]
Thanks Mac, that did the trick.
LOL, was "Bonking" my head, I knew I was missing something.
Was missing the per-verbal forest by only seeing the tree.
Thanks again for all the help everyone.
Hope you all have a happy holiday season.


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

[eluser]combatCoder[/eluser]
Any ideas why this is not validating?
Code:
$this->load->library('form');
    $type = array(
        'default'  =>    '--- Select a Report ---',
        'user'     =>    'Create an User Report',
        'errors'   =>    'Create an Errors Report',
        'office'   =>    'Create an Office Report',
        'eom'      =>    'Create an EOM Report'
    );
        
    $this->form->open('picker/index','picker')
    ->select('type',$type,'Please Select the desired Report:','default','','onchange="this.form.submit();"')
    ->validate();
    if($this->form->valid)
    {
        echo 'Thunderbirds are GO!';
    } else {
        echo 'Houston we have a problem';
    }

Does anyone know if there is a issue with using the onchange to submit and not a button?


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

[eluser]Sinclair[/eluser]
[quote author="macigniter" date="1261584854"][quote author="Sinclair" date="1261581311"]And I just got nothing on the screen. What could be wrong?[/quote]

Everything you posted is correct. So if you really get nothing on the screen it looks like you have an error somewhere else in your controller. Did you validate your php?[/quote]

Hi, the problem was the <?= ?> instead of <? echo ?>.

Another problem I have that I got no solution. There is possible to list in a dropdow box the values from a database request?

The array from database request is like this:

Code:
Array ( [0] => Array ( [id_orientacao] => A ) [1] => Array ( [id_orientacao] => B ) [2] => Array ( [id_orientacao] => C ) )

How can I send this to a dropdown box?


Best Regards,