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-14-2010

[eluser]jesusOmar[/eluser]
[quote author="Frank Rocco" date="1280969944"]I tried your demo login.
Getting an error.

A PHP Error was encountered
Severity: Warning

Message: call_user_func_array() expects parameter 2 to be array, string given

Filename: libraries/Form.php

Line Number: 1991[/quote]

call_user_func_array expects and array as the second parameter, I am not very familiar with this but to fix it all I did was convert the string to an array:
Code:
$this->form->onsuccess('redirect', array('controller/action'));

Hope this helps someone out and that the documentation or a fix is available soon.

--jO


Form Generation Library - El Forum - 12-02-2010

[eluser]jcq[/eluser]
What is the current status of the model() functionality in version 1.0.1? Even in simplified tests I am unable to get it to work. As best as I can tell, $this->model gets properly set when the function is called, but by the time that _load_model() is called, $this->model is null. This means that it fails this test (line 1952):
Code:
if ($this->_posted && count($this->model))
When that happens, the model validation never takes place. Have others encountered this? Has there been a change from the functionality listed in the documentation on this?


Form Generation Library - El Forum - 12-05-2010

[eluser]seanloving[/eluser]
[quote author="jcq" date="1291331987"]What is the current status of the model() functionality in version 1.0.1? Even in simplified tests I am unable to get it to work. As best as I can tell, $this->model gets properly set when the function is called, but by the time that _load_model() is called, $this->model is null. This means that it fails this test (line 1952):
Code:
if ($this->_posted && count($this->model))
When that happens, the model validation never takes place. Have others encountered this? Has there been a change from the functionality listed in the documentation on this?[/quote]

The ->model() method gets called after regular form validation is successful, including any callbacks. And validation happens automatically on submit (when a user clicks submit).

Can you figure out where your validation fails? If it fails then ->model() never gets called

SL


Form Generation Library - El Forum - 12-05-2010

[eluser]seanloving[/eluser]
[quote author="jesusOmar" date="1284510853"]

call_user_func_array expects and array as the second parameter, I am not very familiar with this but to fix it all I did was convert the string to an array:
Code:
$this->form->onsuccess('redirect', array('controller/action'));

Hope this helps someone out and that the documentation or a fix is available soon.

--jO[/quote]

I fixed the "call_user_func_array expects and array as the second parameter" problem in similar way by adding one line of code shown below:

old
Code:
else
{
    $this->_do_onsuccess_matches('', $func['values'], $func['rules']);
}

new
Code:
else
{
    $this->_do_onsuccess_matches('', $func['values'], $func['rules']);
    $func['values'] = array( 0 => $func['values'] );
}

I guess this is hacking. Am I supposed to "extend the library" or something?

SL


Form Generation Library - El Forum - 12-05-2010

[eluser]seanloving[/eluser]
->onsuccess($fcn, $url) works just fine when $fcn='redirect'.

But what other functions can I use with ->onsuccess() ??

Where and how do I look in the Library to find out?

Thanks
SL


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

[eluser]darnold[/eluser]
Mac,

Is there a way to put sections of the form in different places in the view? Here is an example:

Let's say I have a page with tabs that I want to edit.
Code:
<form>
<div id="tabs">
    <a href="#main">Main Fields</a>
    <a href="#seo">SEO Fields</a>
</div>
<div id="main">
  // title input
  // Description input
  // Etc
  // Submit
</div>
<div id="seo">
  // Seo Title Input
  // Seo Description input
  // Etc
  // Submit
</div>
&lt;/form&gt;

This is a very scaled down example, but basically I want to keep most of the HTML out of my controller by having blocks like this:

Code:
$this->form
    ->open('add')
    ->text('title', '', 'required|trim|max_length[120]|xss_clean')
    ->text('description', '', 'required|trim|max_length[120]|xss_clean');

$data['form_main'] = $this->form->get();

$this->form
    ->text('seo_title', '', 'required|trim|max_length[120]|xss_clean')
    ->text('seo_description', '', 'required|trim|max_length[120]|xss_clean');

$data['form_seo'] = $this->form->get();

This way I can split it up in my views! Is there any way to do what i'm thinking, am I approaching it incorrectly?

Any thoughts would be appreciated!

Thanks,
David

[Mod Edit:Edited in true content, Akismet false positive.]


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

[eluser]Cristian Gilè[/eluser]
If the model class is in a subfolder, the statement at line 1964 fails:

Code:
$this->CI->{$model['name']}->{$model['method']}($this, $model_data);

because

Code:
{$model['name']}

also includes the path, not only the model name.

I suggest to insert this condition after the model loading (1962)

Code:
if (($last_slash = strrpos($model['name'], '/')) !== FALSE)
{
    $model['name'] = substr($model['name'], $last_slash + 1);
}

so the _load_model() function becomes:

Code:
function _load_model()
{
    if ($this->_posted && count($this->model))
    {
        foreach ($this->model as $model)
        {
            // combine data provided with POST data (validated at this time)
            $model_data = array_merge($model['data'], $_POST);

            // add file upload data
            $model_data = array_merge($model_data, $this->_data);
                
            $this->CI->load->model($model['name']);
        
            //we check if the model is in a subfolder
            if (($last_slash = strrpos($model['name'], '/')) !== FALSE)
            {
                $model['name'] = substr($model['name'], $last_slash + 1);
            }

            $this->CI->{$model['name']}->{$model['method']}($this, $model_data); // $this = form library handle
        }
    }
}

Hope this help somebody.

Cheers


Form Generation Library - El Forum - 12-27-2010

[eluser]Mantra of Doom[/eluser]
Great library! This will really help with my application which can get pretty form-heavy.

I did run into an issue that I can't wrap my brain around, I'm sure I must be doing something wrong but I've looked over this code all day and can't figure it out.

I use Ion Auth as my auth library and when trying to create or update users, I get this error:

Quote:A Database Error Occurred
Error Number: 1054
Unknown column 'Array' in 'field list'
UPDATE `meta` SET `location` = 'here', `time_zone` = Array, `fav_games` = 'games
', `bio` = 'bio'

Administrator of site
' WHERE `user_id` = '1'

time_zone is a dropdown list of timezones that was generated with codeigniter's date helper function timezone_menu(). Now that I am integrating this library though, I wasn't sure how to integrate timezone_menu into my registration form. I tried to work around it by just making my own select. If I don't change it from the default value, the form submits properly and writes to the database. If I change the timezone to a different value, the form gives the above error.

Controller:
Code:
function register(){
        $this->load->model('player_model');
        $data = $this->player_model->general();
        $zones = array( //loads the values for the timezone menu
                        'UM10' => '(UTC -10:00) Hawaii-Aleutian Standard Time, Cook Islands, Tahiti',
                        'UM9' => '(UTC -9:00) Alaska Standard Time, Gambier Islands',
                        'UM8' => '(UTC -8:00) Pacific Standard Time, Clipperton Island',
                        'UM7' => '(UTC -7:00) Mountain Standard Time',
                        'UM6' => '(UTC -6:00) Central Standard Time',
                        'UM5' => '(UTC -5:00) Eastern Standard Time, Western Caribbean Standard Time',
                        );
                        
        // The Registration Form
        $this->form
        ->fieldset('Register')
        ->open('player/register')
        ->text('username', 'Username', 'required|trim|alpha_numeric|xxs_clean') //field name, label, rules
        ->text('email', 'Email', 'required|trim|valid_email|xxs_clean') //field name, label, rules
        ->password('password', 'Password', 'required|trim|alpha_numeric|xxs_clean') //field name, label, rules
        ->password('password_confirm', 'Password Confirm', 'required|trim|matches[password]|xxs_clean') //field name, label, rules
        ->text('location', 'Location', 'trim|xxs_clean') //field name, label, rules
        ->select('timezones', $zones, 'Time Zone', 'UM5') // field name, options array, label, selected
        ->textarea('fav_games','Favorite Games','required|trim|xxs_clean') //field name, label, rules
        ->textarea('bio','Player Bio','trim|xxs_clean') //field name, label, rules
        ->submit('Register')
        ->reset()
        ->model('player_model','create_user') //call model for registration
        ->onsuccess('redirect', array('player/player_list'));
        
        $data['form'] = $this->form->get();
        $data['errors'] = $this->form->errors;
        $data['websubtitle'] = "Register";

        $data['content'] = 'player/create_user';
Model:
Code:
// Register the player
    function create_user(&$form, $data){
        
        $username     = $data['username'];
        $password     = $data['password'];
        $email        = $data['email'];
        $additional_data = array(
                                'location'     => $data['location'],
                                'time_zone' => $data['timezones'],
                                'fav_games' => $data['fav_games'],
                                'bio'        => $data['bio'],
                                );
        $this->ion_auth->register($username, $password, $email, $additional_data);
        }



Form Generation Library - El Forum - 12-27-2010

[eluser]seanloving[/eluser]
@mantra I think the FGL ->select() method returns an array so just change the one line of your model to this:

Code:
'time_zone' => $data['timezones'][0],



Form Generation Library - El Forum - 12-27-2010

[eluser]Mantra of Doom[/eluser]
@seanloving
Thank you! That worked and it was so simple!