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 - 05-16-2011

[eluser]k7faq[/eluser]
Looking at the code, I stand corrected. The Error, if set for "inline" will only appear following the field.

Looking at the code you would need to search for $this->_make_error(); and change the order in each field type.

You will see something like:
function text()
{
$atts = $this->_filter_atts('input');
$el = $this->_make_label('before');
$el .= $this->field_prefix.form_input($atts).$this->field_suffix;
$el .= $this->_make_label('after');
--> $el .= $this->_make_error();
return $this->element_prefix.$el.$this->element_suffix;
}

Theoretically if you move the line with "$el .= $this->_make_error();" up in the order of processing such as:
function text()
{
$atts = $this->_filter_atts('input');
$el = $this->_make_label('before');
--> $el .= $this->_make_error();
$el .= $this->field_prefix.form_input($atts).$this->field_suffix;
$el .= $this->_make_label('after');
return $this->element_prefix.$el.$this->element_suffix;
}

This would case the error to be generated and listed before the field but following the label.

Hope this helps.


Form Generation Library - El Forum - 05-17-2011

[eluser]tieungao[/eluser]
Thanks so much for your clearly instruction,

So we not have option to control without break into Library code.

Because i scare for later uppdate maybe have, so i hope have option to change it.

But ok your solution is exactly what i want to this time.

Thanks again for your kindly help!


Form Generation Library - El Forum - 05-23-2011

[eluser]tieungao[/eluser]
I got strange error with this library :

Code:
<div style="border: 1px solid rgb(153, 0, 0); padding-left: 20px; margin: 0pt 0pt 10px;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined index: class</p>
<p>Filename: libraries/Form.php</p>
<p>Line Number: 533</p>

</div>

my application/config/form.php

Code:
&lt;?php

$config['nameasid'] = TRUE;

$config['replace'] = 'FALSE|TRUE|TRUE';

$config['xss_clean_post'] = TRUE;

$config['group_prefix']     = '';        // wraps around checkgroups and radiogroups
$config['group_suffix']     = '';
$config['element_prefix']     = '<p>';        // wraps around all elements
$config['element_suffix']     = '</p>';
$config['label_prefix']     = '';        // wraps around labels
$config['label_suffix']     = '';
$config['field_prefix']     = '';         // wraps around fieldsets (inside), inputs, buttons, textareas, selects, captchas & recaptchas
$config['field_suffix']     = '';

$config['error_open'] = '';
$config['error_close'] = '';

$config['error_string_open'] = '';
$config['error_string_close'] = '';

$config['error_class'] = '';

$config['error_inline'] = FALSE;
$config['error_inline_open'] = '';
$config['error_inline_close'] = '';

$config['error_flag'] = '';

$config['globals'] = array();


$config['defaults'] = array();

$config['recaptcha_api_server']            = 'http://api.recaptcha.net';
$config['recaptcha_api_secure_server']    = 'https://api-secure.recaptcha.net';
$config['recaptcha_ssl']                = 'FALSE';
$config['recaptcha_verify_server']        = 'api-verify.recaptcha.net';
$config['recaptcha_key_public']            = '';    // Complete with your key
$config['recaptcha_key_private']        = '';    // Complete with your key
$config['recaptcha_theme']                = 'white';
$config['recaptcha_lang']                = 'en';    // Valid language codes on http://recaptcha.net/apidocs/captcha/client.html

/* End of file form.php */
/* Location: ./application/config/form.php */

my controller :
Code:
//change password
    function change_password()
    {
        $data['title'] = 'Change password';
        
        $this->load->library('form');
        
        $this->form
        ->open('admin/change_password')
        ->fieldset()
        ->password('old','Old Password','trim|required','','class=text-input')
        ->password('new','New Password','trim|required','','class=text-input')
        ->password('new_confirm','Confirm New Password','required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[new_confirm]','','class=text-input')
        ->submit('Change','login','class=button')
        ->html('<div class="clear"></div>');
        
        
        $data['form'] = $this->form->get();        
        $data['errors'] = $this->session->flashdata('message');        
        if ($this->form->valid)
        {
            
            $post = $this->form->get_post(TRUE);
            
            $identity = $this->session->userdata($this->config->item('identity', 'ion_auth'));
            $change = $this->ion_auth->change_password($identity, $post['old'], $post['new']);
            if ($change)
            { //if the password was successfully changed
                $this->session->set_flashdata('message', $this->ion_auth->messages());
                $this->logout();
            }
            else
            {
                $data['errors'] = $this->ion_auth->errors();
                $data['content'] = 'admin/change_password';
                $this->load->view('admin/template', $data);
            }            
        }
        else
        {
            //$data['errors'] = $this->form->errors;            
            $data['content'] = 'admin/change_password';
            $this->load->view('admin/template', $data);
        }        
    
    }



Form Generation Library - El Forum - 05-24-2011

[eluser]Infinitation[/eluser]
New question regarding the form generation library. I couldn't find it the documentation or in searching the forums, but is there a way to designate what select option is selected? I'm working on an edit screen and while I can get my custom select dd working, I cannot figure out how to have it preselect the option that it is.

Any help would be appreciated!

[Of course when I post this I figure it out that I overlooked the documentation, been staring at the screen too long!]


Form Generation Library - El Forum - 05-27-2011

[eluser]Unknown[/eluser]
It is likely that this has been reported before, but I found a little bug in 1.0.4.

Checkboxes (did not check on radio boxes) do not repopulate.

Line 1737 of Form_validation.php holds the error.

Code:
// If the data is an array output them one at a time.
//     E.g: form_input('name[]', set_value('name[]');
if (is_array($this->_field_data[$field]['postdata']))
{
    return array_shift($this->_field_data[$field]['postdata']);
}

This does not work for the form_generation library which needs all of the values every time.

My quick fix was to comment out this code, but there should be a in library fix. Perhaps something that stores the previous values? Thoughts?


Form Generation Library - El Forum - 06-05-2011

[eluser]Unknown[/eluser]
I am loving this library so far and have not found any bugs in it. I'm currently modifying the tank_auth class to use this form library and I noticed this library does not have support for captchas. Is the captcha element planned in an upcoming release? The tank_auth library provides support for Re-Captcha. It might be a quick solution.

I began learning the CI framework yesterday or I would try to update this library to include the captcha element. I might have to anyway Wink

*EDIT*
And I dive in and see the function for recaptcha element creation and then I notice it's documented too!!! lol


Form Generation Library - El Forum - 06-10-2011

[eluser]Unknown[/eluser]
Hy all,

I found a little bug in the form generator. When you try to repopulate a multiple select with multiple values only one option gets selected. This can be fixed by changing line 644 of the library (Form.php) from:

Code:
$el .= $this->field_prefix.form_dropdown($this->name, $this->options, $this->selected, $atts).$this->field_suffix;

to:

Code:
if (count($this->atts["selected"]) > 1)
{
    $el .= $this->field_prefix.form_dropdown($this->name, $this->options, $this->atts["selected"], $atts).$this->field_suffix;
}
else
{
    $el .= $this->field_prefix.form_dropdown($this->name, $this->options, $this->selected, $atts).$this->field_suffix;
}

Hope this helps anyone so they don't need to spend an hour debugging the (absolutely great) library. I hope this will be fixed in the next release.

Gr

Sandhje Bouw


Form Generation Library - El Forum - 06-15-2011

[eluser]Mat-Moo[/eluser]
I'm working on a form that has some quite complex form validation at the moment (Sections that open and close with required or not depending on other values). At present I do the complex validation in my model callback (Before saving), however if the validation fails then the model is not called and my additional errors are not shown. It would seem a nice extra feature to add a extra_validation() method that is called during your validation process with (&$form, $data) so that this would not be in the model but in the controller and all errors shown at the same time. (Does this make sense?


Form Generation Library - El Forum - 06-15-2011

[eluser]marcogmonteiro[/eluser]
Loved your library, well made and well documented Smile keep it up. I'll probably give it a go on my next CI project Smile


Form Generation Library - El Forum - 06-22-2011

[eluser]Mat-Moo[/eluser]
Hmmm, I'm using the latest version and I've got a problem with Muti-selects not showing all the options selected after validation failed. Only the top items gets picked - any ideas? Sad