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 - 01-13-2010

[eluser]happydude[/eluser]
I tried that... It did not change anything...


Form Generation Library - El Forum - 01-13-2010

[eluser]macigniter[/eluser]
[quote author="happydude" date="1263366995"]
The problem I am having with this is that when I click the submit button regardless of whether the data validates (and updates the database) or does not, it is the old database values that get populated as default values in the fields..... until the next edit of the same row comes up.[/quote]

Question: So your form initially populates the values from the database, then you type in some new values and submit the form. If the form is INvalid, still the old database values are being repopulated??


Form Generation Library - El Forum - 01-14-2010

[eluser]happydude[/eluser]
[quote author="macigniter" date="1263395978"][quote author="happydude" date="1263366995"]
The problem I am having with this is that when I click the submit button regardless of whether the data validates (and updates the database) or does not, it is the old database values that get populated as default values in the fields..... until the next edit of the same row comes up.[/quote]

Question: So your form initially populates the values from the database, then you type in some new values and submit the form. If the form is INvalid, still the old database values are being repopulated??[/quote]

Exactly...

Probably due to the way FGL handles user-specified default values.


Form Generation Library - El Forum - 01-14-2010

[eluser]macigniter[/eluser]
[quote author="happydude" date="1263481214"]
Exactly...

Probably due to the way FGL handles user-specified default values.[/quote]

That's strange... check out the demo form. There's some default text in the textarea. If you type in something else and submit it doesn't re-populate the default...


Form Generation Library - El Forum - 01-14-2010

[eluser]happydude[/eluser]
Then, it could be the way my code is structured... I'll try to make it follow the pattern in the example.

Does the demo form use the $this->form->valid condition?


Form Generation Library - El Forum - 01-14-2010

[eluser]macigniter[/eluser]
[quote author="happydude" date="1263487423"]Then, it could be the way my code is structured... I'll try to make it follow the pattern in the example.

Does the demo form use the $this->form->valid condition?[/quote]

That's how the demo handles it:

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

if ($this->form->valid)
{
    // get the validated and xss cleaned (TRUE) post data as an array
    $post = $this->form->get_post(TRUE);

    // do stuff with post vars
    
    // redirect to success page
    redirect('welcome/success');
}
else
{
    // write the errors to the $data array
    // NOTE: this must be done after $form->get()
    $data['errors'] = $this->form->errors;    
}

$this->load->view("welcome", $data);



Form Generation Library - El Forum - 01-14-2010

[eluser]hugle[/eluser]
what version of LIB are you using?
what PHP version?


Form Generation Library - El Forum - 01-14-2010

[eluser]macigniter[/eluser]
[quote author="hugle" date="1263489458"]what version of LIB are you using?
what PHP version?[/quote]

It's the current 1.0 version with PHP 5.2.11

Try using $this->form->get() BEFORE the if ($this->form->valid) (get() automatically validates the form, so no need for calling ->validate())

Then, do a redirect upon successful form submission to load the newly updated values from the db...


Form Generation Library - El Forum - 01-14-2010

[eluser]hugle[/eluser]
[quote author="happydude" date="1263487423"]Then, it could be the way my code is structured... I'll try to make it follow the pattern in the example.

Does the demo form use the $this->form->valid condition?[/quote]

Hello
have you solved your problem?


Form Generation Library - El Forum - 01-17-2010

[eluser]seanloving[/eluser]
Fetch an inventory list and display it in a table.

In the "QTY" column I want to call adjust to get the text box portion of the form:
Code:
function adjust( $val, $caller )
    {
        // use this form element to adjust the quantity of a particular inventory item
        ${'form_'.$caller} = new $this->form();
        ${'form_'.$caller}->open('path')
            ->text( 'qty_'.$caller,'','required|trim|max_length[3]', $val );
    }
in the "ACTIONS" column I want to call adjust_submit to show the submit button of the same form.
Code:
function adjust_submit( $caller )
    {
        ${'form_'.$caller}->submit('Submit', 'sub_'.$caller)
            ->validate();
        $data['form_'.$caller.'_data'] = ${'form_'.$caller}->get();
        $data['form_'.$caller.'_errors'] = ${'form_'.$caller}->errors;
        $data['caller']=$caller;
        $this->load->view('form', $data);

    }

At the second call (to adjust_submit) I'm getting this error:

Code:
Undefined variable: form_0
Fatal error: Call to a member function submit() on a non-object

How do I work this?

--Sean Loving